编写一个Angular子组件,并且不能说服父组件捕获通过@Output发出的值。引发错误,即接收器_co.pinEvent未定义。但是,在初始化期间,调试器显示它已成功进行调用。所以这不是一个简单的错字。
按照我能找到的所有指南和问题,将其简化为最小的示例,但仍然无法使它正常工作。组件参考_co似乎指向的不是home组件。
...
import { KeypadComponent } from '../keypad/keypad.component';
@NgModule({
...
declarations: [HomePage, KeypadComponent]
})
export class HomePageModule {
digits: number;
title: string;
change: any;
constructor() {
}
pinEvent($event) {
console.log(JSON.stringify($event));
}
}
<ion-content>
<ble-lock-keypad (pinValue)="pinEvent($event)"></ble-lock-keypad>
Once the component is visible, any event emitted
from child causes this pinEvent() call to fail on
an undefined reference.
</ion-content>
@Component({
selector: 'ble-lock-keypad',
templateUrl: './keypad.component.html'
})
export class KeypadComponent {
@Output() pinValue: EventEmitter<string> = new EventEmitter<string>();
constructor() {
}
handleInput(key: string) {
this.pinValue.emit(key);
}
}
<ion-button (click)="handleInput('1')">1</ion-button>
真的不愿意看到此错误:
TypeError:_co.pinEvent不是函数。 (在“ _co.pinEvent($ event)”中,“ _ co.pinEvent”未定义)
谁能指出出什么问题了?