angularinputangular2-templateangular2-components

@Input in Angular 4


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;

Solution

  • 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.