简体   繁体   中英

@output eventemitter is not working-angular 14

Hi i want to call parent function via child component and i used eventemitter, every thing seems fine but my function is not getting called.

this is child component.ts


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>

this is parent component.ts

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

function wasn't called on imported child component!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM