angular binding code example
Example 1: angular binding
<input [disabled]="condition ? true : false">
<input [attr.disabled]="condition ? 'disabled' : null">
Example 2: angular property binding
// component.ts
@Component({
templateUrl: 'component.html',
selector: 'app-component',
})
export class Component {
name = 'Peter';
updateName() {
this.name = 'John';
}
}
Example 3: Bidirectionnal model binding
content_copy
<app-sizer [(size)]="fontSizePx"></app-sizer>
Example 4: property binding angular documentation
// component.ts
@Component({
templateUrl: 'component.html',
selector: 'app-component',
})
export class Component {
name = 'Peter';
updateName() {
this.name = 'John';
}
}
// component.html
<p>My name is {{name}}</p>
<button (click)="updateName()">Update button</button>
Example 5: angular property binding
import { Component } from "@angular/core";
@Component({
selector: 'app-example',
template: `
<div>
<input [value]='myText'></span>
</div>
`
})
export class AppComponent {
myText: string = "Hello World";
}