【发布时间】:2016-05-20 22:56:03
【问题描述】:
我找不到@Component() 如何绑定到类的明显证据。
它如何知道组件与RedditArticle 类而不是Article 类绑定?切换了两个班的位置后,就乱了。这是否意味着我们需要绑定的类后面应该跟着对应的组件?
import { bootstrap } from "angular2/platform/browser";
import { Component } from "angular2/core";
@Component({
selector: 'reddit-article',
template: `
<div class="row">
<div class="col-md-3"></div>
<div>Points: {{article.votes}}</div>
<div class="col-md-9"></div>
<!--<div class="row">-->
Title: {{article.title}}
Link: {{article.link}}
<button (click)="voteUp()">upvote</button>
<button (click)="voteDown()">downvote</button>
<!--</div>-->
</div>
`
})
class RedditArticle {
article: Article;
constructor() {
this.article = new Article('angular2', 'google.com', 0);
}
voteUp() {
this.article.votes++;
}
voteDown() {
this.article.votes--;
}
}
class Article {
title: string;
link: string;
votes: number;
constructor(title: string, link: string, votes: number) {
this.title = title;
this.link = link;
this.votes = votes;
}
}
【问题讨论】:
标签: components angular