角度事件发射器错误: 预期的0类型参数,但得到1

我得到类型错误,“期望0类型参数,但得到1”,尽管遵循本教程到一个 T。 Https://youtu.be/i317bhehzkm?t=57s

我已经说明:

  newUserInfoComplete:boolean = false

然而,我在这一行得到了上面在 <boolean>上指定的错误:

  @Output() newUserInfoCompleteEvent = new EventEmitter <boolean> ();

同样,如果我简单地省略 <boolean>,我会得到这个错误:

Argument of type 'boolean' is not assignable to parameter of type 'string'.

还有这个 NewUserInfoComplete 在下面划线:

this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);

下面是我的组成部分:

import { Component, OnInit, Output } from '@angular/core';
import { slideToRight } from '../../../../router.animations';
import { Router, ActivatedRoute, UrlSegment } from '@angular/router';
import { EventEmitter } from 'protractor';


@Component({
selector: 'app-new-user-input',
templateUrl: './new-user-input.component.html',
styleUrls: ['./new-user-input.component.css'],
animations: [slideToRight()]
})
export class NewUserInputComponent implements OnInit {


newUserInfoComplete:boolean = false


@Output() newUserInfoCompleteEvent = new EventEmitter <boolean> ();


constructor(private router: Router, r: ActivatedRoute) {
r.url.subscribe((s: UrlSegment[]) => {
console.log("url", s); //https://vsavkin.com/angular-router-understanding-router-state-7b5b95a12eab
});
}


ngOnInit() {
}






sendNewUserInfoComplete(){
this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);
}




displaySibling() {
console.log(this.router);
this.router.navigate(['../', { outlets: { newuserorginfo: ['newuserorginfo'] } }])
}


closeBlade() {
this.router.navigate([{ outlets: { newuserinput: null } }]);
}


}
52512 次浏览
import { Component, Output } from '@angular/core';
import { slideToRight } from '../../../../router.animations';
import { Router, ActivatedRoute, UrlSegment } from '@angular/router';
import { EventEmitter } from 'protractor';


@Component({
selector: 'app-new-user-input',
templateUrl: './new-user-input.component.html',
styleUrls: ['./new-user-input.component.css'],
animations: [slideToRight()]
})
export class NewUserInputComponent {


newUserInfoComplete = false;
@Output() newUserInfoCompleteEvent = new EventEmitter <boolean> ();


constructor(private router: Router, r: ActivatedRoute) {
r.url.subscribe((s: UrlSegment[]) => {
console.log("url", s);
});
}
sendNewUserInfoComplete(){
this.newUserInfoCompleteEvent.emit(!!this.newUserInfoComplete);
}




displaySibling() {
console.log(this.router);
this.router.navigate(['../', { outlets: { newuserorginfo: ['newuserorginfo'] } }])
}


closeBlade() {
this.router.navigate([{ outlets: { newuserinput: null } }]);
}


}

try this

Try importing EventEmitter from Angular instead of from protractor:

import { Component, OnInit, Output, EventEmitter } from '@angular/core';

I forgot to check my imports! Darn. I was using PROTRACTOR'S event emitter and not angular core Event Emitter

import { EventEmitter } from '@angular/core';
import { Component, OnInit, Output } from '@angular/core';
import { slideToRight } from '../../../../router.animations';
import { Router, ActivatedRoute, UrlSegment } from '@angular/router';


@Component({
selector: 'app-new-user-input',
templateUrl: './new-user-input.component.html',
styleUrls: ['./new-user-input.component.css'],
animations: [slideToRight()]
})
export class NewUserInputComponent implements OnInit {


newUserInfoComplete = false;


@Output() newUserInfoCompleteEvent = new EventEmitter<boolean>();


constructor(private router: Router, r: ActivatedRoute) {
r.url.subscribe((s: UrlSegment[]) => {
console.log("url", s); //https://vsavkin.com/angular-router-understanding-router-state-7b5b95a12eab
});
}


ngOnInit() {
}






sendNewUserInfoComplete() {
this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);
}




displaySibling() {
console.log(this.router);
this.router.navigate(['../', { outlets: { newuserorginfo: ['newuserorginfo'] } }])
}


closeBlade() {
this.router.navigate([{ outlets: { newuserinput: null } }]);
}


}

You just got the imports wrong, you need to import EventEmitter from @angular/core

import { EventEmitter } from @angular/core
import { EventEmitter, Component, OnInit, Output } from '@angular/core';

Please make sure EventEmitter imported on @angular/core otherwise error.

I was mistaken. I was importing-

 import { EventEmitter } from 'events';

so got error getting

Don't import with events like below:

import { EventEmitter } from 'events';

Try to import like below:

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

Don't import EventEmitter from 'protractor', import it from '@angular/core'.
Why it has happened: because you used EventEmmiter before importing it, so in that case it automatically imports from 'protractor' module.

just replace the automatically added import statement :

    import * as EventEmitter from 'events';

with

    import { Component, OnInit, Output ,EventEmitter} from '@angular/core';

245

Import EventEmitter from Angular instead of from stream:

import { Component, OnInit, Output, EventEmitter } from '@angular/core';

not this

import { EventEmitter } from 'stream'; “>”