CCBet
CCBet

Reputation: 426

String interpolation in Angular

My app.component.ts code:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css'],
})
export class AppComponent implements OnInit {
  isDisabled = false;

  ngOnInit(): void {
    setTimeout(() => {
      this.isDisabled = !this.isDisabled;
    }, 2000);
  }
}

My app.component.html code:

<input type="text" value="{{ isDisabled }}" disabled="{{ isDisabled }}" />

Q: What's causing the difference in the way these two string interpolations work?

Upvotes: 0

Views: 153

Answers (1)

Ardit
Ardit

Reputation: 376

disabled will disable an element whether it is true or false, it's presence means that the element will be disabled.
Angular will not add the disabled element at all for [disabled]="variable" if variable is false.

Upvotes: 2

Related Questions