【发布时间】:2020-01-03 20:25:14
【问题描述】:
我已经下拉了
userList =[ { id: "0",name: "ALL"},{id: "1",name: "Smith"},{id: "2",name: "Smith"},{
id: "3", name: "RAM"}];
when select ALL option i need to get all id's of user into string object.
string str = {1,2,3}(不包括0)
<mat-select placeholder="User"(ngModelChange)="modelChanged($event)" formControlName="user" name="user">
<mat-option *ngFor="let data of userList" [value]="data.id">{{data.name}} </mat-option>
</mat-select>
我的打字稿:
onChangeRole(): void {
this.userRoleService.getUserDetails().subscribe((response: Response) => {
if (response.failure) {
this.modalPopupService.openPopup(AlertComponent, { message: response.error });
} else {
this.userList = response.result;
const all = {
id: 0,
name: 'ALL'
};
this.userList.splice(0, 0, all);
}
});
}
modelChanged(res): void {
const userType = res;
if (userType === 0) {
this.userType = ???;
} else {
this.userType = userType;
}
}
this.usertype 之上是任何属性。
如何将 id 列表放入字符串对象中?
【问题讨论】:
标签: arrays filter angular-material angular7 dropdown