1

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>

2 Answers 2

5

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..
Sign up to request clarification or add additional context in comments.

Comments

3

Use Angular property binding with the brackets notation to make sure that the parameter is evaluated as an expression:

[disabled]="hasExistingEnrollmentPeriods"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.