Angular’s [disabled] binding seems to work with true or false

Angular’s [disabled] binding seems to work with true or false

In html, disabled means disabled, but in Angular’s property binding, if the variable is true or false, it will toggle between enabled and disabled.

[disabled]='variable name'

app.component.ts

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

@Component({
  selector: 'app-root',
  template:
  `
  <div style="text-align:center">
    <input type="text" maxlength="8" [disabled]="aaa" value="テキスト"><br>
    <button type="button" (click)="onClick()">ボタン</button>
  </div>
  `,
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  aaa = false;
  onClick() {
    this.aaa = !this.aaa;
  }
}

The variable called aaa is toggled between true and false by pressing the button.

Angular's [disabled] binding seems to work with true or false

コメント

Discover more from 株式会社CONFRAGE ITソリューション事業部

Subscribe now to keep reading and get access to the full archive.

Continue reading

Copied title and URL