サンプル API からデータをフェッチする単純なアプリがあります。ディレクティブをコンポーネントとして定義するときに何が問題なのかを理解しようとしています:
app.ts
import {Component, View, bootstrap, For} from 'angular2/angular2';
import {ArticlesSvc} from 'services/articlesSvc';
import {ArticleItem} from 'directives/ArticleItem';
@Component({
selector: 'main-app',
injectables: [ArticlesSvc]
})
@View({
template: `<p *for="#post of posts">{{ post.title }} <article-item [body]="post.body"></article-item></p>`,
directives: [For,ArticleItem]
})
class MainComponent {
posts: Array<string>;
constructor(articlesSvc: ArticlesSvc) {
this.posts = [];
articlesSvc.get('http://jsonplaceholder.typicode.com/posts').then((data) => {
this.posts = data;
});
}
}
bootstrap(MainComponent);
そして、ここにArticleItem
コンポーネントがあります:
import {Component, View} from 'angular2/angular2';
@Component({
selector: 'article-item',
properties: ['body']
})
@View({
template: `<p>{{ body }}</p>`
})
export class ArticleItem {
body:string;
}
何らかの理由で、Unexpected number
エラーが発生します。これら 2 つのコンポーネントを正しく接続するにはどうすればよいですか? 独自のビューでサブコンポーネントを定義するのは適切な方法ですか?