
上QQ阅读APP看书,第一时间看更新
Binding click event
AngularJS provides an event based directive, ng-click, that can bind a click event to a method in an associated controller. Angular achieves the same by using native DOM elements which can be targeted with the ( ) syntax and it accomplishes this by combining One-way Data Binding with the event binding.
AngularJS:
<button ng-click="vm.showBook()"> <button ng-click="vm.showBook($event)">
Angular:
<button (click)="showBook()"> <button (click)="showBook($event)">
Notice that in Angular, the target event click is defined inside the parentheses and the method from the component is specified in quotes.