0
  <nb-select [(ngModel)]="selectedOption" 
  (click)="getProdDetails(p.ProductName,p.Brand)" ngDefaultControl>
  <nb-option [value]="p.Size" class="text-nowrap" [hidden]="hide">
     {{ p.Size }} : + {{ p.SaleRate | currency: "INR": 'symbol' : 
 '1.0-0'}}
  </nb-option>
  <nb-option class="text-nowrap" [value]="i.Size" *ngFor="let i of 
     prodDetails"[hidden]="!hide">
     {{ i.Size }} : + {{ i.SaleRate |currency: "INR": 'symbol' : 
 '1.0-0'}}
  </nb-option>
  </nb-select>



 .ts code:

  selectedOption: any;
  getData(){
  this.ProdData = [];
 this.commonservice.get('api').subscribe((data) => {
    const temp = data.data["data"];
   // by using for loop i am iterating through each value of array 
   and pushing it in ProdData
    this.ProdData.push(temp);
   )}
   }
 Similarly in <nb-select> the p is getting values from ProdData 
 Array.
 getProdDetails(name,brand){
 this.prodDetails = [];
 this.commonService
  .get(url)
  .subscribe((res) => {
    const temp = res.data["data"];
     )} 
 }

请参考下图。首先nb-option,我从不同的数组中获取值。其次nb-option,我从方法中定义的数组中获取值 getProdDetails()。当我单击 2nd 的选项值时,nb-option它会将所有选择选项的值替换为选定的选项。

我希望它会有所帮助!另外,如果我不使用 [(ngModel)] 它工作正常。但我需要使用它来绑定值并在我的 .ts 文件中使用它。每次选择一个选项时,我都想在选择框中显示所选项目。

[1]:https://i.stack.imgur.com/s8ANd.png

4

0 回答 0