“Type 'EventEmitter' is not generic” ERROR in angular

前端 未结 4 724
鱼传尺愫
鱼传尺愫 2021-02-03 16:54

I\'m currently following a tutorial and the tutorial is making use of EventEmitter. The code goes like this

@Output() ratingClicked: EventEmitter<         


        
相关标签:
4条回答
  • 2021-02-03 17:10

    When using Visual Studio Code, The IDE automatically imports EventEmitter from Node.js.

    import { EventEmitter } from "events";
    

    In this case you'll have to manually change it to angular core module

    import { EventEmitter } from "@angular/core";
    
    0 讨论(0)
  • 2021-02-03 17:12

    I was doing the same tutorial and faced the same issue.

    It is a problem with an import. EventEmitter must be imported from @angular/core

    Use:

    import { EventEmitter } from '@angular/core';
    

    This will fix it.

    0 讨论(0)
  • 2021-02-03 17:14

    In visual studio code when your try to listen to user click event from your html file of the component

    @Output() event: EventEmitter<string> = new EventEmitter<string>();

    it automatically import this to the component import { EventEmitter } from '@angular/event' instead of import { EventEmitter } from '@angular/core'.

    Resource: https://ultimatecourses.com/blog/component-events-event-emitter-output-angular-2

    0 讨论(0)
  • 2021-02-03 17:24

    You are probably using the node native EventEmitter from node/index.d.ts i.e.

    import { EventEmitter } from 'events';
    

    Fix

    Change the import to the one from angular:

    import { EventEmitter } from '@angular/core';
    
    0 讨论(0)
提交回复
热议问题