Angular2 disabled input

431 阅读1分钟
It looks like you're using the disabled attribute with a reactive form directive. If you set disabled to true when you set up this control in your component class, the disabled attribute will actually be set in the DOM for you. We recommend using this approach to avoid 'changed after checked' errors.


form = new FormGroup({
   first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
   last: new FormControl('Drew', Validators.required)
});

browsers should not allow submitting elements that are disabled;


fixed:

this.userForm.controls['UserID'].disable({ onlySelf: true })
this.userForm.controls['UserID'].enable({ onlySelf: false })