Sahin Erbay
Sahin Erbay

Reputation: 1014

Passing Data From Parent to Child Component

I need to pass the data from parent to child using input. The variable i would like to pass is coming from *ngFor.

I would like to do like this. Currently is not working; Cannot read property 'subject' of undefined

 <ul *ngFor="let item of data">
   <li> {{item.id}}</li>
 </ul>
 <ubi-story-side [rec]='item.id'></ubi-story-side>

Upvotes: 0

Views: 515

Answers (2)

Bo Chen
Bo Chen

Reputation: 156

creating @Inpust inside of child component

child.component.ts

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

export class ChildComponent {
  @Input() public rec: any;
}

Upvotes: 0

Meir
Meir

Reputation: 14395

Your ubi-story-side is outside of the *ngFor and hence the item variable is unknown there. Which item do you want to pass to the story-side?

Upvotes: 2

Related Questions