angular 管道

昔憶落落發表於2019-03-11
管道將資料作為輸入並將其轉換為所需的輸出(實現對資料的格式化)。

管道可以接受任意數量的可選引數來微調起輸出,要向管道新增引數,請使用冒號(:)跟隨管道名稱,然後使用引數值,如:date: "MM/dd/yy",如果管道接受多個引數,請用冒號分割值如:slice:1:5。

<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>複製程式碼


相關文章