Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find name +'Input'. any Angular 2

I am trying to get @Input to work with Typescript in Angular 2. I am getting the following error and I don't understand why.

[ts] Cannot find name 'Input'. any

Below is the code from that component.

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

@Component({
   selector: 'app-item',
   templateUrl: './app-item.component.html',
   styleUrls: ['./app-item.component.css']
})
export class AppItemComponent implements OnInit {
      @Input item; //TypeScript complains here. 

      constructor() { }

      ngOnInit() {}
}

The project and component were both created using the Angular CLI. Why can't TypeScript figure out the @Input decoration?

like image 455
user961714 Avatar asked Apr 08 '17 04:04

user961714


2 Answers

You need to add this,

import {Component, Input} from '@angular/core';
like image 94
Sajeetharan Avatar answered Oct 01 '22 20:10

Sajeetharan


In my case I already had:

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

So, when I tried to use:

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

It didn't work.

What I had to do was import like that (Without the word Component)

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

And it worked just fine

like image 37
Marcielli Oliveira Avatar answered Oct 01 '22 20:10

Marcielli Oliveira