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?
You need to add this,
import {Component, Input} from '@angular/core';
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With