我使用角度4和初始值4.3.0显示对象;然而,当我选择一个项目时,整个列表选择而不是一次只选择一行..我如何定义元素是错误的?
<p-listbox formControlName="userRole" [options]="this.userRoleItems" [(ngModel)]="selectedUserRoles" multiple="multiple" [style]='{"width":"650px"}' checkbox="checkbox" filter="filter"
>
<ng-template let-userRole let-i="index" pTemplate="item" optionLabel="userRole.description">
{{userRole.code}} <span style="float:right">{{userRole.description}}</span>
</ng-template>
</p-listbox>
export class UserRole {
public id: number;
public name: string;
public code: string
public description: string;
public branchId: number;
public branchName: string;
}
答案 0 :(得分:1)
您应该在对象中使用value
属性。
目前,组件中没有optionValue
属性。
示例代码:
import { Component, OnInit } from '@angular/core';
export class UserRole {
value: number;
rolename: string;
}
@Component({
selector: 'my-app',
templateUrl: 'app/app.template.html'
})
export class AppComponent implements OnInit {
userRoleItems: UserRole[] = [{value: 2, description: 'test'},
{value: 3, description: 'test'},
];
selectedUserRoles:any[] = [];
ngOnInit() {
}
}