Reputation: 561
i want to set output value in component . write this code for output :
export class OutputComponentComponent implements OnInit {
@Output() public childEvent = new EventEmitter();
@HostListener('window:mousemove', ['$event'])
onMouseMove(event: MouseEvent) {
this.functinoOutput();
}
private functinoOutput() {
this.childEvent.emit('value')
}
}
and i use this component in appcomponent.html
<app-ouput (childEvent)="showCordinate($event)"></app-ouput>
but it show me this error :
Error: @Output childEvent not initialized in 'ResizableComponentComponent'.
whats the problem ? how can i solve this problem ???
Upvotes: 0
Views: 951
Reputation: 2164
I think you did not import EventEmitter
in your TS file or import that one from wrong library. If not then try the code given below.
import { EventEmitter } from '@angular/core';
If you are using import { EventEmitter } from 'events';
then please replace your import with my one.
NOTE: If you still facing problem please let me know.
Upvotes: 1
Reputation: 147
Have you tried to declare a flag?
export class OutputComponentComponent implements OnInit {
initialized = false;
@Output() public childEvent = new EventEmitter();
@HostListener('window:mousemove', ['$event'])
onMouseMove(event: MouseEvent) {
if (this.inizialited) {
this.functinoOutput();
}
}
ngOnInit(): void {
this.inizialited = true;
}
private functinoOutput() {
this.childEvent.emit('value')
}
}
Optional: try to declare better the @Output
@Output() search: EventEmitter<ClassOrSomething> = new EventEmitter(false);
Upvotes: 1