我正在使用angular6 multi-select,它有一个来自角度服务的对象数组中的项目列表,ngOnInit就像这样传递到multi-select:
this.sensorTypes = [
{ label : "Power", value : "P"},
{ label : "Current", value : "C"},
{ label : "Voltage", value : "V"}
]
我想在multi-select表单加载时默认设置 2 个值。为此,我绑定ngModel在multi-select那个变量上,我正在ngOnInit像这样设置值
this.selectedAttributes = [
{label : "Current", value : "C"},
{label : "Voltage", value : "V"}
]
在我的 component.html 中,我这样创建multi-select:
<div class="form-group row">
<div class="col-sm-10">
<ng-select
[ngClass]="'ng-select'"
[(ngModel)]="selectedAttributes"
[ngModelOptions]="{standalone: true}"
[options]="sensorTypes"
[multiple]="true">
</ng-select>
</div>
</div>
但是默认情况下,在多选中未设置值。