Reputation: 1819
I have a disabled ngBootstrap datepicker. How can I disable this conditionally based on the value of a variable I have, hasExistingEnrollmentPeriods
?
I've tried disabled="hasExistingEnrollmentPeriods"
but that always sets disabled to true even when the expression is false.
<input class="form-control" placeholder="MM-DD-YYYY" name="effecDate" ngbDatepicker #ed="ngbDatepicker"
(click)="ed.toggle(); DetectChange()" (ngModelChange)="onSelectEffectiveDate($event)" formControlName="effectiveDate" disabled>
<div class="input-group-append">
<button class="btn btn-outline-secondary calendar" (click)="ed.toggle()" type="button">
<i class="fal fa-calendar-alt"></i>
</button>
</div>
Upvotes: 1
Views: 2063
Reputation: 10204
You need to use [disabled]
, not disabled
.
disabled="hasExistingEnrollmentPeriods"
means assign string value "hasExistingEnrollmentPeriods" to "disabled" attribute
.[disabled]="hasExistingEnrollmentPeriods"
means assign value of "hasExisstingEnrollmentPeriods" to "disabled" attribute.
.Upvotes: 5
Reputation: 73751
Use Angular property binding with the brackets notation to make sure that the parameter is evaluated as an expression:
[disabled]="hasExistingEnrollmentPeriods"
Upvotes: 3