I 前端代码
<ng-select formControlName="constituencyId" placeholder="Select Constituency" (change)='onContituencyChanged($event)'> >
<ng-option *ngFor="let op of this.getAllConsituencies"
[value]="op.id"
[attr.typename]="op.constituencyTypeName" >
{{op.code}} {{op.name}}
</ng-option>
</ng-select>
<label>Constituency Name</label>
后端代码
onContituencyChanged(evt: any) {
console.log("targeted obj of constituency. " ,evt);
}
我只是在获取所选项目的价值,而不是一个完整的目标事件。
实际上我在我的角度中使用 ng-select 下拉列表我想要两个 perfomr 两个操作首先在更改我想获得对添加到下拉列表的自定义属性的访问以执行一些逻辑
试试这个:
Ints:
myNgSelect: NgSelectComponent;
@ViewChild(NgSelectComponent) private set ngSelect(
ngSelect: NgSelectComponent
) {
if (!ngSelect) {
return;
}
this.myNgSelect = ngSelect;
this.mySelectInputBox = ngSelect.filterInput.nativeElement;
console.log('ng select =>', ngSelect.filterInput.nativeElement);
}
现在,在你的改变事件中:
onContituencyChanged(evt: any) {
console.log("targeted obj of constituency. " ,evt);
if (evt && this.mySelectInputBox) {
this.mySelectInputBox.value = evt.name;
console.log('on myChange', this.myNgSelect.filterInput.nativeElement); //this defines your selected element's attributes.
}
}