国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

angular4筆記系列之內置指令小結

2024-05-06 15:28:05
字體:
來源:轉載
供稿:網友

內置指令

內置屬性型指令

屬性型指令會監聽和修改其它HTML元素或組件的行為、元素屬性(Attribute)、DOM屬性(Property)。

NgClass

形式:[ngClass]="statement"

通過綁定到NgClass,可以同時添加或移除多個類。

setCurrentClasses() { this.currentClasses = {  'saveable': this.canSave,  'modified': !this.isUnchanged,  'special': this.isSpecial };}<div [ngClass]="currentClasses">This div</div>

NgStyle

形式:[ngStyle]="statement"

NgStyle綁定可以同時設置多個內聯樣式。

setCurrentStyles() { this.currentStyles = {  'font-style': this.canSave   ? 'italic' : 'normal',  'font-weight': !this.isUnchanged ? 'bold'  : 'normal',  'font-size':  this.isSpecial  ? '24px'  : '12px' };}<div [ngStyle]="currentStyles">This div</div>

NgModel

形式:[(ngModel)]="statement"

使用[(ngModel)]雙向綁定到表單元素。

<input [(ngModel)]="currentHero.name">

使用 ngModel 時需要 FormsModule

內置結構型指令

NgIf

形式:*ngIf="statement"

<app-hero-detail *ngIf="isActive"></app-hero-detail>

NgFor

形式:*ngFor="statement"

<div *ngFor="let hero of heroes">{{hero.name}}</div>

NgSwitch

形式:[ngSwitch]="statement"

<div [ngSwitch]="currentHero.emotion"> <app-happy-hero *ngSwitchCase="'happy'" [hero]="currentHero"></app-happy-hero> <app-sad-hero *ngSwitchCase="'sad'" [hero]="currentHero"></app-sad-hero> <app-unknown-hero *ngSwitchDefault [hero]="currentHero"></app-unknown-hero></div>

NgSwitch實際上包括三個相互協作的指令:NgSwitch、NgSwitchCase 和 NgSwitchDefault

模板引用變量 ( #var )

模板引用變量通常用來引用模板中的某個DOM元素,它還可以引用Angular組件或指令或Web Component。

<input #phone placeholder="phone number"><button (click)="callPhone(phone.value)">Call</button>

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持錯新站長站。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 云霄县| 淮滨县| 宁波市| 东台市| 清水河县| 宜兴市| 瑞丽市| 石河子市| 阿城市| 扶余县| 赣榆县| 南宫市| 周至县| 沂源县| 乌拉特后旗| 鞍山市| 仁布县| 彭泽县| 朝阳区| 天台县| 贵州省| 太湖县| 西林县| 山东| 搜索| 理塘县| 北票市| 游戏| 蓝山县| 巴塘县| 和龙市| 开鲁县| 定州市| 天峨县| 沛县| 扬中市| 汕尾市| 天全县| 德令哈市| 芷江| 临夏市|