我收到一个错误,上面写着
错误类型错误:_co.onKey 不是函数 at Object.eval [as handleEvent]
import { Component } from "@angular/core";
@Component({
selector: "sandbox",
templateUrl: "sandbox.component.html",
styleUrls: ["./sandbox.component.css"]
})
export class SandboxComponent {
fireEvent(e){
console.log(e.type);
}
}
.html
<input (keyup)="fireEvent($event)">
看起来你只需要在输入标签中添加type="name"
。
TS :
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular 5';
fireEvent(e){
console.log(e,e.keyCode);
}
}
.HTML:
<input type="name" (keyup)="fireEvent($event)">
样品在这里 : https://stackblitz.com/edit/angular-jbym58?file=app%2Fapp.component.ts