首页 > 其他 > 详细

How to Repeat a List

时间:2015-07-21 01:06:05      阅读:183      评论:0      收藏:0      [点我收藏+]

1 import directive [For]

import {Component, Template, bootstrap, For} from ‘angular2/angular2‘;

  it is important

2 define your list

class MyApp {

    constructor() {
        this.myName = ‘Jackey‘;
        this.myFriends = [
            {name: ‘Jackey1‘, age: 25},
            {name: ‘Jackey2‘, age: 26}
        ];
    }
}

3 repeat you list to UI

@Template({
    inline: ‘<h1>{{myName}}</h1>‘ +
    ‘<ul>‘ +
    ‘<li *for="#friend of myFriends">{{friend.name}} {{friend.age}}</li>‘ +
    ‘</ul>‘,
    directives: [For]

})

  USE *for="#xx of XXX" .. REMEMBER to inject [for] directive

4 the whole page code:

import {Component, Template, bootstrap, For} from ‘angular2/angular2‘;

@Component({
    selector: ‘my-app‘
})

@Template({
    inline: ‘<h1>{{myName}}</h1>‘ +
    ‘<ul>‘ +
    ‘<li *for="#friend of myFriends">{{friend.name}} {{friend.age}}</li>‘ +
    ‘</ul>‘,
    directives: [For]

})

class MyApp {

    constructor() {
        this.myName = ‘Jackey‘;
        this.myFriends = [
            {name: ‘Jackey1‘, age: 25},
            {name: ‘Jackey2‘, age: 26}
        ];
    }
}

bootstrap(MyApp);

  

How to Repeat a List

原文:http://www.cnblogs.com/lihaozhou/p/4663024.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!