Reputation: 1534
I have problems with binding a dynamic "required" to an input. The input is always invalid and does not interact with the required attribute. Please have a look at my Plunkr. May be I'm missing something?
@Component({
selector: 'my-app',
template: `
<form #heroForm="ngForm">
Set Required <input type="checkbox" [(ngModel)]="req">
<input #inp ngControl="something" type="text" [(ngModel)]="myModel" [required]="req" #spy><br>
required: {{req}}<br>
required attribute: {{!!spy.attributes.getNamedItem("required")}}<br>
classes: {{spy.className}}<br>
</form>
`
})
Upvotes: 3
Views: 474
Reputation: 657366
Currently required
need to be added statically otherwise Angular won't initialize the validator
<input #inp ngControl="something" type="text" [(ngModel)]="myModel" required #spy><br>
This is planned to be changed.
Upvotes: 1