Cannot find name + "Login". any angular 2

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

[ts] Could not find login name. any

Below is the code for this 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 created using the Angular CLI. Why can't Typescript define an @Input decoration?

+11
source share
3 answers

You need to add this,

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

In my case, I already had:

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

So, when I tried to use:

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

This did not work.

What I needed to do was import (without the word Component)

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

And it worked just fine

+1

@Marcielli, - .

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

Everything will be all right with you. Optionally, adding an input module in a separate import statement is fine, but usually you should either import all the components from the module in one statement, or each in separate statements.

0
source

Source: https://habr.com/ru/post/1016399/


All Articles