@output eventemitter不能正常工作



嗨,我想通过子组件调用父函数,我使用了eventemitter,一切似乎都很好,但我的函数没有被调用。

这是子组件。


import { Component, EventEmitter, forwardRef, HostBinding, Input,Output,ViewChild } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
@Component({
selector: 'month-date-picker',
templateUrl: './month-date-picker.component.html',
styleUrls: ['./month-date-picker.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => MonthDatePickerComponent),
multi: true
}
]
})
export class MonthDatePickerComponent implements ControlValueAccessor {
@Output() testfunction : EventEmitter<any>  = new EventEmitter()
prevent(e){
this.testfunction.emit(null)
}

this is child component.html

<button class="btn btn-outline-secondary dropdown-toggle-split" ngbDropdownToggle (click)="prevent($event)">
<div class="calendar" aria-hidden="true"></div>
</button>

this is parent component.html

<month-date-picker *ngIf="dmanuyear&& compshow == true" name="manufactureYeardup" [manudata]="dmanuyear" formControlName="manufactureYeardup" (checkdate)="checkdate($event)"  (testfunction)="funcheck($event)">
</month-date-picker>

这是父组件。

public funcheck(event):void{
console.log(event)
alert("hiiiiii")
}

在导入的子组件上没有调用函数!

<month-date-picker *ngIf="dmanuyear&& compshow == true" name="manufactureYeardup" [manudata]="dmanuyear" formControlName="manufactureYeardup" (checkdate)="checkdate($event)" (testfunction)="funcheck($event)"> </month-date-picker>

相关内容

  • 没有找到相关文章

最新更新