雙向繫結 (Two Way Binding)
Template語法:
<element [(ngModel)]="變數名稱"></element>
程式碼範例:
1.在Component.ts中加入變數myModel
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'example-component',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent implements OnInit {
myModel = "";
constructor() { }
ngOnInit() {
}
}
2.在Template中使用雙向繫結該變數
<input type="text" [(ngModel)]="變數名稱"> <button>確定</button>