简体   繁体   中英

Passing object through components using service in angular 2

I have one doubt regarding the components communication using services.

Now I have one parent component, where I am rendering the list array of objects in parent component using NgFor. Whenever I click any particular item, a function gets triggered and specific object is passed in that function.

Then I am using subject and Observables to load that particular data in a child component. Everything looks fine, but here am trying to access that particular item before the triggering of the function, so in console.log am getting the errors like Cannot read property 'movie_id' of undefined)

add an *ngIf to child component regarding the particular data.. that way Angular doesn't try to access the 'movie_id' container object before it exists..

for example, if you have myObj = { ..., movie_id: 'tarzan' } add a *ngIf="myObj"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM