Angular EventEmitter Issue: Received 1 argument when expecting 0 types

I encountered an unexpected type error stating, "Expected 0 type arguments, but got 1," despite closely following a tutorial. https://youtu.be/I317BhehZKM?t=57s

The specified code snippet is as follows:

newUserInfoComplete:boolean = false

The error occurs at <boolean> in this line:

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

If I remove <boolean>, a different error arises:

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

Furthermore, 'this.NewUserInfoComplete' is highlighted in the subsequent code block:

this.newUserInfoCompleteEvent.emit(this.newUserInfoComplete);

Below is the component in question:

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 } }]);
  }

}

Answer №1

Consider using the @angular/core module to import EventEmitter instead of relying on the protractor library:

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

Answer №2

Oops! I completely forgot to double-check my imports before running into issues. Instead of using Angular Core's Event Emitter, I mistakenly used PROTRACTOR'S 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 } }]);
  }

}

Answer №3

Just a heads up, when you need to use EventEmitter, make sure to import it from '@angular/core' instead of 'protractor' as mentioned in the highest voted answer.

The reason behind this confusion is that if you utilize EventEmmiter prior to importing it, it will automatically assume to import from the 'protractor' module.

Answer №4

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 {

  newUserInformationComplete = false;
  @Output() newUserInformationCompleteEvent = new EventEmitter <boolean> ();

  constructor(private router: Router, r: ActivatedRoute) {
    r.url.subscribe((s: UrlSegment[]) => {
      console.log("URL segments:", s);
    });
  }
  sendNewUserInformationComplete(){
    this.newUserInformationCompleteEvent.emit(!!this.newUserInformationComplete);
  }


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

  closePanel() {
    this.router.navigate([{ outlets: { newUserInput: null } }]);
  }

}

give this a shot

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

I encountered a type error while working on a small project involving Graphql and TypeScript

An error message is displaying that indicates a missing property 'type' in the code snippet provided. The required type 'GraphQLFieldConfig<any, any, any>' expects this property to be present. The code contains 11 fields with an ...

Tooltip z-index hidden behind another element

I've encountered an issue where tooltips on adjacent elements are being obscured by headers of subsequent elements. I've attempted adjusting the z-index, but it hasn't resolved the problem - the root cause eludes me. .header { vertical- ...

Solving the issue of localizing the Datetime picker

My date input seems to be saving incorrectly in the database. When I enter a date like 18/02/2020, it gets saved as 17/02/2020 22:00:00. Is this a time zone issue? How can I fix this problem and thank you. Also, if I want to save the date with UTC, how do ...

Detecting flat surfaces using Three.js for any object

Curious about finding flat surfaces of objects in a scene? I am looking to draw PlanGeometry on any detected flat surface near my object, but unsure how to detect them. Any tips or suggestions for libraries that can assist with this? ...

Can you explain the concept of a mapped type and its practical applications?

What is the function of this? And when would be the best scenario to utilize it? ...

Making calls to an Angular GRPC API through an Envoy proxy

Having trouble connecting to the GRPC server from the UI via Envoy. Here's the code snippet for the Envoy proxy: static_resources: listeners: - address: socket_address: address: 0.0.0.0 port_value: 8888 filter_chains: ...

The Route export field does not accept authOptions as a valid value

My authOptions code is currently running smoothly on my localhost environment. import NextAuth, { NextAuthOptions } from "next-auth"; import GoogleProvider from "next-auth/providers/google"; export const authOptions: NextAuthOptions = ...

How to retrieve a targeted row from a Material Table using Angular

In the HTML code snippet provided below, I have a mat-card element containing a table with various row elements: <mat-card> <mat-card-header> <mat-card-title>Results</mat-card-title> </mat-card-header> <mat-card-c ...

Is React Typescript compatible with Internet Explorer 11?

As I have multiple React applications functioning in Internet Explorer 11 (with polyfills), my intention is to incorporate TypeScript into my upcoming projects. Following the same technologies and concepts from my previous apps, I built my first one using ...

Unveiling the Secrets of Interacting with SVG animateMotion Events using Angular

TheanimateMotion element triggers three events: onbegin, onrepeat, and onend. In vanilla JavaScript, I can attach an event listener like this: <circle r="15" fill="red"> <animateMotion dur="10s" begin="indefinite" re ...

Loading data into Angular Reactive Forms: Easy steps to preload form inputs with information

I have encountered a challenge while trying to incorporate a forum into my website. Initially, I struggled with template-driven forms but eventually shifted to Reactive forms. As I navigate between these two approaches on my site, I have identified a drawb ...

Exploring mathematical capabilities with AngularJS

I need assistance with a scope function that involves cost and formatted value data retrieved from an API. The formatted value can be in varying currencies such as Baht, PHP, CHF, etc., not just limited to Euro or USD. My goal is to perform mathematical o ...

What causes BehaviorSubjects in Angular RXJS to emit multiple values?

click here to see the image descriptionUsing BehaviorSubject for sharing data between components in my app has led to a performance problem caused by multiple emissions of the same value. For example, when I make an HTTP call to fetch a team object from th ...

How well does a collective Angular Material module perform when it incorporates numerous Component modules?

Have you ever explored the Angular Material component usage guide? It recommends creating a shared module to include multiple components. I'm curious about how shared modules are utilized. Utilizing an Angular Shared Module import {MatButtonModule} fr ...

Tips for handling various HTTP requests until a response is received

For my application, I have a need to make multiple http calls before proceeding to create certain objects. Only after all the http requests have received responses from the servers can I process the results and construct my page. To handle this scenario, ...

Tips for creating a draggable Angular Material dialog

Has anyone been able to successfully implement draggable functionality in an Angular Material Dialog? I've spent a considerable amount of time searching for a definitive answer but have come up empty-handed. Any insights or guidance would be greatly a ...

Generate a new data structure by pairing keys with corresponding values from an existing

Imagine having a type named Foo type Foo = { a: string; b: number; c: boolean; } Now, I am looking to create a type for an object containing a key and a value of a designated type T. The goal is for the value's type to be automatically determin ...

Changing of expression is detected upon entering but not when clicking

I encountered an issue in my Angular 7 application where pressing the enter key in an input field triggers an error, while clicking on the search button does not: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. ...

What is the best way to dynamically load a third-party module in Angular 2?

One way to dynamically load third-party modules in Angular 2, especially for production builds using Angular CLI with Ahead-of-Time (AOT) compilation, is by leveraging webpack's functionality. Webpack generates build files for both eagerly and lazily ...

How can I designate inner schemas as optional in Ajv?

Here is a sample schema using ajv (v8.11.2) import Ajv, { JSONSchemaType } from "ajv"; interface MyType { myProp?: OtherType; } interface OtherType { foo: string; bar: number; } const otherSchema: JSONSchemaType<OtherType> = ...