Angular 2 Template Syntax
Victor Savkin
1015

Thank youfor your great article. I have a question

i have 2 component: Component1, and Component2

In component 1 i get an array of object post name posts and want to access to that array from component 2 so i do like that

<coponent2 [allPost]=”posts”></component2>

But in the component 2 i do like this

export class Component2 implements OnInit {

@Input allPost: Post[];

ngOnInit() {

console.log(“all post: ” + this.allPost);

console.log(“number of post: ” + this.allPost.length);

}

}

I get the result : all post: undefined and error: cannot acess property length of undefined.

It seem like i cant use allPost as a local variable in the component 2.

Is there any way to use allPost as local variable in the component 2? Can you help me? Thank in advance!