小编Sam*_*rts的帖子

ng重复组件

我有两个组件,一个是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;
    }
}
Run Code Online (Sandbox Code Playgroud)

另一个是新闻源:

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 …
Run Code Online (Sandbox Code Playgroud)

components angular

12
推荐指数
1
解决办法
2万
查看次数

标签 统计

angular ×1

components ×1