Besides @Input (), we can also use properties on the @Component, to pass the data.
Import {Component, View, Ngfor, Input} from ' Angular2/angular2 '; @Component ({selector:' Reddit-article '}) @View ({directives: [], Template: '<article> <div class= "votes" >{{article.votes}}</div> <div class= "main" > `}) Export class Redditarticle {@Input () article:article; Voteup () { This. Article.voteup (); return false; } votedown () { This. Article.votedown (); return false; }}
Works the same as:
Import {Component, View, Ngfor, Input} from ' Angular2/angular2 '; @Component ({selector:' Reddit-article ', properties: [' Article ']}) @View ({directives: [], Template: '<article> <div class= "votes" >{{article.votes}}</div> <div class= "main" > `}) Export class Redditarticle {article:article; Voteup () { This. Article.voteup (); return false; } votedown () { This. Article.votedown (); return false; }
[Angular 2] Passing data to components with ' properties '