码迷,mamicode.com
首页 > 其他好文 > 详细

angular4-常用指令

时间:2017-09-01 09:56:29      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:gif   use   user   示例   port   bsp   select   let   angular4   

ngIf 指令(它与 AngularJS 1.x 中的 ng-if 指令的功能是等价)

<div *ngIf="condition">...</div>

ngFor 指令(它与 AngularJS 1.x 中的 ng-repeat 指令的功能是等价的)

<li *ngFor="let item of items;">...</li>

 

ngIf 与 ngFor 指令使用示例

import { Component } from ‘@angular/core‘;

@Component({
    selector: ‘sl-user‘,
    template: `
    <div *ngIf="showSkills">
        <ul>
            <li *ngFor="let skill of skills">
                {{skill}}
            </li>
        </ul>
    </div>
    `
})
export class UserComponent {
    showSkills: boolean;
    skills: string[];

    constructor() {
        this.showSkills = true;
        this.skills = [‘AngularJS 1.x‘, ‘Angular 2.x‘, ‘Angular 4.x‘];
    }
}

 

angular4-常用指令

标签:gif   use   user   示例   port   bsp   select   let   angular4   

原文地址:http://www.cnblogs.com/avidya/p/7461312.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!