本文作者: jsweibo
本文链接: https://jsweibo.github.io/2019/12/01/Angular%E4%B8%AD%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86/
摘要
本文主要讲述了:
- 监听事件
- 按键修饰符
正文
监听事件
写法和内联事件处理器非常相似
即:向 HTML 特性传递一个函数调用
示例:监听点击事件
my-angular/src/app/app.component.html
1 | <button type="button" (click)="onClick($event)">Click Me</button> |
my-angular/src/app/app.component.ts
1 | import { Component } from '@angular/core'; |
示例:监听键盘输入
my-angular/src/app/app.component.html
1 | <input type="text" [value]="keywords" (input)="onInput($event)" /> |
my-angular/src/app/app.component.ts
1 | import { Component } from '@angular/core'; |
按键修饰符
示例:只有当【Enter 键】弹起时,onClickSearchBtn()
才会执行
my-angular/src/app/app.component.html
1 | <input |
my-angular/src/app/app.component.ts
1 | import { Component } from '@angular/core'; |
参考资料
本文作者: jsweibo
本文链接: https://jsweibo.github.io/2019/12/01/Angular%E4%B8%AD%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86/
本文对你有帮助?请支持我


- 本文链接: https://jsweibo.github.io/2019/12/01/Angular%E4%B8%AD%E7%9A%84%E4%BA%8B%E4%BB%B6%E5%A4%84%E7%90%86/
- 版权声明: 除非另有说明,否则本网站上的内容根据署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0) 进行许可。