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'];
    }
}
原文地址:https://www.cnblogs.com/avidya/p/7461312.html