@Input in Angular 4

Ramya picture Ramya · Sep 4, 2017 · Viewed 29.3k times · Source

I am new to Angular 4.As per my understanding, @Input is used to pass values to a component. But when I use it as mentioned below it doesn't work.

my-file.component.html
    <h1 [user] = "currentuser"></h1>

my-file.component.ts
    @Input() 
    user : string;

Answer

Plog picture Plog · Sep 4, 2017

It means you can pass the string input into your my-file component itself not any HTML element (i.e. h1 in your case) within the component itself.

i.e. in the parent component you can call something like:

<my-file [user]="currentuser"></my-file>

Then this value of user will be available to be used within your my-file child component.