我正在使用角度2选择。
我正在使用formControlName。
<form class="edit" [formGroup]="addcameraForm" (ngSubmit)="onSubmit(addcameraForm.value)" class="form-horizontal">
<div class="albumname">
<label for="input01">Select user</label>
<ng-select style="color:#000;"
formControlName="selectMultiple"
[options]="options"
[multiple]="true"
placeholder="Select Assets">
</ng-select>
</div>
<div class="form-group">
<div class="col-sm-10">
<button class="btn btn-success btn-auth" [disabled]="!addcameraForm.valid">Add Camera</button>
</div>
</div>
</form>
这是我的组件。
ngOnInit() {
this.addcameraForm = this.fb.group({
ACCESS_USERS : this.fb.array([]),
APART_ID:[''],
CAMERA_ACCESS_CODE:[''],
CAMERA_ACCESS_URL: [''],
CAMERA_CODE: [''],
CAMERA_NAME: [''],
CAMERA_PASSWORD:[''],
CAMERA_STATUS:[''],
CAMERA_USERNAME:[''],
selectMultiple:['']
});
}
我得到这个错误
Error: There is no FormControl instance attached to form control element with name: 'selectMultiple'
我如何解决这个问题。
请建议我,
答案 0 :(得分:4)
试试这个: -
<ng-select style="color:#000;"
[formControl]="addcameraForm.controls['selectMultiple']"
[options]="options"
[multiple]="true"
placeholder="Select Assets">
</ng-select>