Angular2:组件如何绑定到 class?

Angular2: how can component bind to class?

我找不到 @Component() 如何绑定到 class 的明显证据。 它如何知道组件与 class RedditArticle 而不是 class Article 绑定?调换两个class的位置后,就乱了。这是否意味着我们需要绑定的 class 后面应该是相应的组件?

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;
    }
}

@Component() 装饰器直接应用于注释后面的 class。

这对所有注释都是一样的。

例如

constructor(@Inject('xxx') private val:string, private zone:NgZone) {}

此处@Inject()绑定到val