我正在使用primeNg - 2.0.3和Angular 2.0.0我正在使用反应形式。我想在我的表单中使用PrimeNg的多重选择功能。我做了以下
Component.html
<div class="form-group">
<label for="cities" class="control-label">Cities</label>
<p-multiSelect [options]="cities" formControlName="selectedCities"></p-multiSelect>
</div>
Component.ts
import {SelectItem} from 'primeng/primeng';
export class CreateKMSControlComponent implements OnInit {
cities: SelectItem[];
selectedCities: FormControl;
ngOnInit() {
this.cities = [];
this.cities.push({label:'New York', value:'New York'});
this.cities.push({label:'Rome', value:'Rome'});
this.cities.push({label:'London', value:'London'});
this.cities.push({label:'Istanbul', value:'Istanbul'});
this.cities.push({label:'Paris', value:'Paris'});
}
this.formGroup = new FormGroup({
selectedCities : this.selectedCities
})
}
但我得到一个错误错误:尝试diff''不确定需要做些什么来解决这个问题。有人可以指导我们。
答案 0 :(得分:0)
import {SelectItem} from 'primeng/primeng';
export class CreateKMSControlComponent implements OnInit {
cities: SelectItem[];
selectedCities: FormControl;
ngOnInit() {
this.cities = [];
this.cities.push({label:'New York', value:'New York'});
this.cities.push({label:'Rome', value:'Rome'});
this.cities.push({label:'London', value:'London'});
this.cities.push({label:'Istanbul', value:'Istanbul'});
this.cities.push({label:'Paris', value:'Paris'});
this.formGroup = new FormGroup({
selectedCities : this.selectedCities
});
}
}
将表单初始化为ngOnInit
方法。