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>复制代码
相关文章
相关标签/搜索