1 回答

TA貢獻(xiàn)1936條經(jīng)驗(yàn) 獲得超7個(gè)贊
父組件
HTML
<nb-box (onCreditChange)="onCreditChange"></nb-box>
TS
onCreditChange($event) { console.log($event) }
子組件
錯(cuò)誤從這里開(kāi)始,因?yàn)?Output 不是一個(gè)函數(shù),它是一個(gè)允許您將事件發(fā)送給父級(jí)的對(duì)象。您需要在子函數(shù)內(nèi)部執(zhí)行一個(gè)函數(shù),并使用輸出對(duì)象發(fā)出。
HTML
<div class="box">
<nb-switch (onChange)="onChangeInChild($event)"></nb-switch>
</div>
TS
import { Component, Input, NgModule, EventEmitter, Output} from '@angular/core';
export class Box extends BoxBase {
@Output() onCreditChange = new EventEmitter<any>()
onChangeInChild(eventObject: any){
this.onCreditChange.emit(eventObject)
}
}
添加回答
舉報(bào)