I am using angular2 cli and this is the way i have setup my form
In the component
export class UsersAddComponent implements OnInit {
ngOnInit() {
this.userForm = this._formBuilder.group({
role: ['', [Validators.required]],
others: this._formBuilder.array([]) //for adding multipe form inputs
});
this.addNewUser();
}
initAddress() {
return this._formBuilder.group({
sendcred: [''], //checkbox needs no validation in my logic
needs_reset: [''], // ''
.....other fields here
});
}
addNewUser() { //this is called whenever add new user button is clicked
const control = <FormArray>this.userForm.controls['others'];
const addrCtrl = this.initAddress();
control.push(addrCtrl);
}
In the html template am using primeng checkbox like this
<p-checkbox formControlName="needs_reset" label="User has to set password"
(onChange)="Onpwdchange()"></p-checkbox>
<p-checkbox formControlName="sendcred" name="send cred" label="Send user
login credentials " (onChange)="Oncredchange()"></p-checkbox>
The methods onpwdchange()
and oncredchange() just have a console.log("clicked")
Whenever i check the checkboxes am getting an error
this.model.push is not a function //i havent implemented push method anywhere
Ive checked on This primeng2 issue but they advice use of disableDeprecatedForms()
and provideForms()
which are not available in angular2 cli
How do i solve this issue
Aucun commentaire:
Enregistrer un commentaire