<input [(ngModel)]="keyword" placeholder="[(雙向繫結)]" (keyup.escape)="onKeyClear()"/> 文字:{{keyword}},字數:{{keyword.length}}ts部分
keyword = ''; onKeyClear() { this.keyword = ""; }參考資料
1.保哥的Angular 開發實戰:從零開始
2.Angular官網
<input [(ngModel)]="keyword" placeholder="[(雙向繫結)]" (keyup.escape)="onKeyClear()"/> 文字:{{keyword}},字數:{{keyword.length}}ts部分
keyword = ''; onKeyClear() { this.keyword = ""; }參考資料
<a on-click="CountPlus($event)">點擊次數{{count}}</a><br /> <a (click)="CountPlus($event)">點擊次數{{count}}</a>ts部分
export class EventBindingComponent implements OnInit { count = 0; CountPlus($event:any) { this.count++; console.log($event); } constructor() { } ngOnInit(): void { } }===============================================================
<input type="text" (keyup)="onKeyClear($event)" /> 字數:{{keywordCount}}ts部分
keyword = ""; keywordCount = 0; onKeyClear(event: KeyboardEvent) { let elm = (<HTMLInputElement>event.target); if (event.key == "Escape") { elm.value = "";//這段要清除掉Html上的文字 this.keyword = ""; } else { this.keyword = elm.value; } console.log(this.keyword); this.keywordCount = this.keyword.length; }參考資料
<a [href]="url" [attr.data-tite]="title">{{title}}</a>ts部分
export class PropertyBindingComponent implements OnInit { title = "{{屬性繫結}}"; url = "http://tw.yahoo.com"; constructor() { } ngOnInit(): void { } }參考資料