angular 管道

管道將數據做爲輸入並將其轉換爲所需的輸出(實現對數據的格式化)。

管道能夠接受任意數量的可選參數來微調起輸出,要向管道添加參數,請使用冒號(:)跟隨管道名稱,而後使用參數值,如:date: "MM/dd/yy",若是管道接受多個參數,請用冒號分割值如:slice:1:5。bash

<p>The hero's birthday is {{ birthday | date:"MM/dd/yy"}}</p> birthday = new Date(1988, 3, 15);複製代碼

<p>The hero's birthday is {{ birthday | date:format }}</p><button (click)="toggleFormat()">Toggle Format</button> toggle = true; // start with true == shortDate get format() { return this.toggle ? 'shortDate' : 'fullDate'; } toggleFormat() { this.toggle = !this.toggle; }複製代碼

<p>The chained hero's birthday is{{ birthday | date:'fullDate' | uppercase}}</p>複製代碼
相關文章
相關標籤/搜索