3
After I upgraded from Angular 7 to Angular 8 in an application the [disabled] stopped working in various parts of the template. And to load the application I needed to change to [attr.disabled]. I still don’t quite understand why 'attr'.'
But anyway disabled in one of the parts of the site ceased to function as before. The idea was that the user could select up to 5 tags within a multi-tag seal. If he selected 5 tags it would be disabled. If he took the selection leaving 4 or less enabled again. And at angle 8 it stopped working and now appears the error below
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.
Example:
form = new FormGroup({
first: new FormControl({value: 'Nancy', disabled: true}, Validators.required),
last: new FormControl('Drew', Validators.required)
});
HTML
...
<div class="form-group col-5 col-md-3" *ngFor="let tag of tags" [attr.disabled]="desabilitar(tag)">
...
Typescript
...
public desabilitar(tag: Tag): boolean {
return !this.exists(tag) && this.tagsEmpresa.length === 5;
}
...