Trang chủ Bài viết Lập trình Frontend Angular 2 căn bản - Bài 11: Stuctural directives
Lập trình Frontend 23/01/2017 5,633 lượt xem

Angular 2 căn bản - Bài 11: Stuctural directives

Angular 2 căn bản - Bài 11: Stuctural directives

Bài này chúng ta sẽ tìm hiểu cách sử dụng của 3 build in directive là ngIf, ngFor và ngSwitch

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

@Component({
    selector:'my-tutorial',
    template:`
    <h2>{{title}}</h2>
    <h3 *ngIf="showLineIf">This ngIf directive line.</h3>
    <div [ngSwitch]="color">
        <p *ngSwitchCase="'red'">This line color is red</p>
        <p *ngSwitchCase="'blue'">This line color is blue</p>
        <p *ngSwitchCase="'green'">This line color is green</p>
        <p *ngSwitchDefault>Invalid color</p>
    </div>

    <ul>
        <li *ngFor="let color of colors">{{color}}</li>
    </ul>
    `
})
export class TutorialComponent{
    public showLineIf = false;

    public color = "23232";

    public colors: string[] = ["red","green","blue"];
}

Chia sẻ:

Bài viết liên quan

Giới thiệu về Angular
08/12/2019 • TEDU

Giới thiệu về Angular

Chào mừng bạn đến với series bài viết hướng dẫn Angular. Series này bao gồm từ Angular 2, 3, 4, 5, 6, 7, 8 và 9. Bao gồm các bước để bắt đầu làm chủ Angular

Đọc thêm
Học ReactJS qua ví dụ
02/06/2019 • Cao Anh Quốc

Học ReactJS qua ví dụ

Tuy chỉ là một thư viện nhưng khi kết hợp hệ sinh thái của React lại ta hoàn toàn có thể gọi ReactJS là một framework và ReactJS là một trong những library/ framework phổ biến nhất hiện nay.

Đọc thêm
Zalo