1

ex: I have ['a', 'b', 'c'] in the select tags, then ['b'] is chosen, I want the next select tag contains only ['a', 'c']

TS file:

orderSelect() { //get all documents from db
    this.orderService.orderSelect().subscribe(data => {
        this.orderArray = new MatTableDataSource(data); 
        this.orderArray.sort = this.sort;
        this.orderArray.paginator = this.paginator;
    });
}

HTML file:

<mat-form-field> 
    <mat-select formControlName="productId" matInput placeholder="Product" #productId required>
        <mat-option *ngFor="let a of productArray" value="{{ a._id }}" (click)="getPrice(i, a.productPrice, a.productQuantity); getTotal(i)">{{ a.productName }}</mat-option>
    </mat-select>
</mat-form-field> 
Kirk Larkin
  • 84,915
  • 16
  • 214
  • 203
C.E James
  • 315
  • 1
  • 5
  • 22
  • 1
    what have you tried until now? – Jota.Toledo Sep 25 '18 at 12:12
  • and what data the array `productArray` contains? – Hussein Sep 25 '18 at 12:12
  • i used this code whenever it clicks an option in select tags this.productArray.splice(index, 1); – C.E James Sep 25 '18 at 12:16
  • the array contains: router.get('/productSelect', (req, res, next) =>{ productSchema.aggregate([ { $lookup: { from: 'supplierschemas', localField: 'supplierId', foreignField: '_id', as: 'supplier' } }, – C.E James Sep 25 '18 at 12:18
  • { $lookup: { from: 'brandschemas', localField: 'brandId', foreignField: '_id', as: 'brand' } }, { $lookup: { from: 'categoryschemas', localField: 'categoryId', foreignField: '_id', as: 'category' } } ], (err, productSchema) =>{ if(err) res.json(err); else res.json(productSchema); }); }); – C.E James Sep 25 '18 at 12:18
  • i tried this code: this.productArray.splice(index, 1); but it removes wrong element in array. then i wan to return the previous element when the deleted form is deleted. this is a reactive form. creates multiple form in a button click – C.E James Sep 25 '18 at 12:21
  • 1
    My recommendation is to create a `Pipe`(filter) and use it in `ngFor`. See [this similar question](https://stackoverflow.com/questions/34164413/how-to-apply-filters-to-ngfor) – leopal Sep 26 '18 at 07:35

0 Answers0