two way binding angular 6 code example
Example 1: property binding angular documentation
@Component({
templateUrl: 'component.html',
selector: 'app-component',
})
export class Component {
name = 'Peter';
updateName() {
this.name = 'John';
}
}
<p>My name is {{name}}</p>
<button (click)="updateName()">Update button</button>
Example 2: angular two way property binding
import { Component } from '@angular/core';
import { FormsModule } from '@angular/forms';
@Component({
selector: 'app-example',
template: `
Enter the value: <input [(ngModel)]='val'>
<br>
Entered value is: {{val}}
`
})
export class AppComponent {
val: string = '';
}