angularjs - How to access Input data passed from parent component in Angular2 -


i have playlist component child component, parent pass in input 'playlist' object of array.

  playlist: {     headerplaylists: array<any>,     bodyplaylists: array<any>   } = {     headerplaylists: [],     bodyplaylists: []   } 

the child component below

@component({   selector: 'playlist',   styleurls: ['app/channel/playlist/playlist.css'],   templateurl: 'app/channel/playlist/playlist.html',   directives: [videoitemcomponent],   inputs: ['playlist'] }) 

my question , in class, how access inputs passed in it's parent component, say, console.log(playlist), there way that?

export class playlistcomponent {    constructor() {    } } 

thierry correct w.r.t. availability of inputs across lifecycle, how works clearer if use @input() on field rather inputs in metadata.

@component({   selector: 'playlist',   styleurls: ['app/channel/playlist/playlist.css'],   templateurl: 'app/channel/playlist/playlist.html',   directives: [videoitemcomponent],  // inputs: ['playlist'] // redundant }) class playlistcomponent implements oninit {   @input() playlist: yourplaylisttype; // i.e. data structure posted    ngoninit(){      // use this.playlist    } } 

note that, largely reason, specifying inputs via @input() preferred on using inputs per ng2 style guide.


Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -