【发布时间】:2016-09-27 23:01:15
【问题描述】:
我有两个组件,一个是 Post:
import {Component} from '@angular/core';
@Component({
selector: 'post',
template: `
<h1>{{title}}</h1>
<p>{{postText}}</p>
`
})
export class Post {
title : string;
postText : string;
constructor(title:string, postText:string) {
this.title = title;
this.postText = postText;
}
}
另一个是新闻源:
import {Component} from '@angular/core';
import {Post} from "./app.post.component";
@Component({
selector: 'news-feed',
template: `
<h1>News Feed</h1>
<ul *ngFor='#post of posts'>
<li *ngFor='#post of posts'>
{{post | json}}
</li>
</ul>
`
})
export class NewsFeed {
posts : Post[];
constructor() {
let p1 = new Post("Post1","Wow greate post");
let p2 = new Post("Such Post", "WoW");
this.posts =[];
this.posts.push(p1);
this.posts.push(p2);
}
}
有没有办法让我使用帖子中的模板重复每个帖子,而不仅仅是使用对象语法或格式化新闻源中的帖子。由于我是 ang2 的新手,所以我可能以错误的方式处理这个问题。任何帮助表示赞赏。
非常感谢。
【问题讨论】:
-
清楚地发布问题你想做什么?
标签: angular components