angular tutorials

Cannot find name ‘Output’ – Angular

I was trying to learn and implement @Input and @Output decorators in Angular. And when I tried @Output, I got the following error Cannot find name ‘Output’ in Angular.

Cannot find name ‘Output’ – Angular

I was trying to use @Output decorator to enable the event “menuItemSelected” to listen to from outside of the HeaderComponent as shown below.


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

   templateUrl: './header.component.html'

export class HeaderComponent {
   collapsed = true;

   @Output() menuItemSelected = new EventEmitter<string>();

   onSelect(menuItem: string) {


Therefore, I have added @Output to the event property “menuItemSelected” to make it listenable from the parent component (for example, AppComponent).


<nav class="navbar navbar-default"> 
    <div class="container-fluid">
        <div class="navbar-header">
                <button type="button" class="navbar-toggle" (click)="collapsed = !collapsed">
                  <span class="icon-bar" *ngFor="let iconBar of [1, 2, 3, 4]"></span>
                <a routerLink="/" class="navbar-brand"></a>
        <div class="navbar-collapse" [class.collapse]="collapsed" (window:resize)="collapsed = true">

            <ul class="nav navbar-nav">
                <li><a href="#" (click)="onSelect('recipes')">Recipes</a></li>
                <li><a href="#" (click)="onSelect('shopping-list')">Shopping List</a></li>

            <ul class="nav navbar-nav navbar-right">
                <li class="dropdown">
                    <a href="#" class="dropdown-toggle" role="button">Manage <span class="caret"></span></a>
                    <ul class="dropdown-menu">
                        <li><a href="#">Save Data</a></li>
                        <li><a href="#">Fetch Data</a></li>

AppComponent template

<app-header (menuItemSelected)="onNavigate($event)"></app-header>
<div class="container">
    <div class="row">
        <div class="col-md-12">
            <app-recipes *ngIf="loadedPage === 'recipes'"></app-recipes>
            <app-shopping-list *ngIf="loadedPage === 'shopping-list'"></app-shopping-list>             

I got the following error

ERROR in src/app/header/header.component.ts:12:5 - error TS2304: Cannot find name 'Output'.

12    @Output() menuItemSelected = new EventEmitter<string>();


Typescript could not figure out the @Outputdecorator and add the import statement.

Therefore, you need to add or modify the following import statement manually in your component class.

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

Now, the above import statement includes Output along with Component and EventEmitter from ‘@angular/core’.

That’s it. The error Cannot find name ‘Output’ should have disappeared.

Hope it helped 🙂


Leave a Reply

Notify of