Angular 4 primeng onChange无效

时间:2018-01-25 19:00:43

标签: angular typescript dropdown primeng

目前我正在实施一种搜索方法,可以从两个下拉列中进行搜索。 我们选择第一列,然后选择第二列。我们有2个筒仓和4个商店,选择第一个筒仓,然后它将显示2个商店,siloId为1,选择第二个筒仓将显示其余2个商店有siloId 2.但是,无论如何修改onChange($ event) ),(onChange)=“onChange($ event.value)似乎永远不会起作用。

这是我的.ts代码

 /*Here is my .ts code*/<br> constructor(
      private router: Router ) {
       this.silos = [
        {label: 'North ASSEMBLY SILO', value:{Id: '1'}},
        {label: 'South ASSEMBLY SILO', value:{Id: '2'}},
        ];           
       this.shops = [          
        {label: 'Assembly N', value:{siloId: '1', Id: '1'}},
        {label: 'Assembly NN', value:{siloId: '1', Id: '2'}},
        {label: 'Assembly S', value:{siloId: '2', Id: '3'}},
        {label: 'Assembly SS', value:{siloId: '2', Id: '4'}},
        ];
                 }
        onChange($event){
          if(event) {
             // No matter what I do, this seems doesn't work....
        }
    }

这是我的.html代码

        <div class="ui-grid-col-3" >   
        <b>DROP DOWN TO SELECT SILOS</b>
        <p-dropdown [options]="silos" [(ngModel)]="selcetedShop" [style]="{'width':'100%'}" filter = "true" (onChange)="onChange($event)">
        </p-dropdown>
    </div>
    <div class="ui-grid-col-3" >    
        <b>DROP DOWN TO SELECT SHOPS</b>
        <p-dropdown [options]="shops" [(ngModel)]="selectedSilo" [style]="{'width':'100%'}" filter ="true">
        </p-dropdown>
    </div>

1 个答案:

答案 0 :(得分:2)

您需要使用 (ngModelChange)

 <p-dropdown [options]="silos" [(ngModel)]="selcetedShop" [style]="{'width':'100%'}" filter = "true" (ngModelChange)="onChange(selcetedShop)" >