Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular EventEmitter Error: Expected 0 type arguments, but got 1

I am getting the type error, "Expected 0 type arguments, but got 1" despite following this tutorial to a T. https://youtu.be/I317BhehZKM?t=57s

I have specified:

  newUserInfoComplete:boolean = false 

yet I am getting the error specified above on <boolean> in this line:

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

Also, if I simply omit <boolean> I get this error:

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

and this.NewUserInfoComplete is underlined here:

this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete); 

Here is my component:

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 } }]);   }  } 
like image 670
imnickvaughn Avatar asked May 23 '18 18:05

imnickvaughn


People also ask

Why EventEmitter is used in angular?

What Is EventEmitter in Angular. EventEmitter is a module that helps share data between components using emit() and subscribe() methods. EventEmitter is in the Observables layer, which observes changes and values and emits the data to the components subscribed to that EventEmitter instance.

How to fix Expected 0 arguments but got 1?

The error "Expected 0 arguments, but got 1" occurs when we pass an argument to a function that doesn't take any arguments. To solve the error define and type the arguments of the function inline or update the function's type in the specific interface or type alias.

What is EventEmitter in angular8?

🎊 Event Emitters in Angular 🎊 Data flows into your component via property bindings and flows out of your component through event bindings. If you want your component to notify his parent about something you can use the Output decorator with EventEmitter to create a custom event.


1 Answers

Try importing EventEmitter from Angular instead of from protractor:

import { Component, OnInit, Output, EventEmitter } from '@angular/core'; 
like image 183
ConnorsFan Avatar answered Nov 08 '22 19:11

ConnorsFan