网站首页 > 基础教程 正文
Angular 2有很多可用于转换数据的过滤器和管道。
小写
这用于将输入转换为所有小写字母。
句法
Propertyvalue | lowercase
参量
没有
结果
该属性值将转换为小写。
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
TutorialName: string = 'Angular JS2';
appList: string[] = ["Binding", "Display", "Services"];
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The name of this Tutorial is {{TutorialName}}<br>
The first Topic is {{appList[0] | lowercase}}<br>
The second Topic is {{appList[1] | lowercase}}<br>
The third Topic is {{appList[2]| lowercase}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
大写
这用于将输入转换为全部大写。
句法
Propertyvalue | uppercase
参量
没有。
结果
该属性值将转换为大写。
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
TutorialName: string = 'Angular JS2';
appList: string[] = ["Binding", "Display", "Services"];
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The name of this Tutorial is {{TutorialName}}<br>
The first Topic is {{appList[0] | uppercase }}<br>
The second Topic is {{appList[1] | uppercase }}<br>
The third Topic is {{appList[2]| uppercase }}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
片
这用于从输入字符串中分片数据。
句法
Propertyvalue | slice:start:end
参量
- start-这是切片应从其开始的起始位置。
- end-这是切片应从其开始的起始位置。
结果
将根据起点和终点位置对属性值进行切片。
例
首先确保在app.component.ts文件中存在以下代码
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
TutorialName: string = 'Angular JS2';
appList: string[] = ["Binding", "Display", "Services"];
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The name of this Tutorial is {{TutorialName}}<br>
The first Topic is {{appList[0] | slice:1:2}}<br>
The second Topic is {{appList[1] | slice:1:3}}<br>
The third Topic is {{appList[2]| slice:2:3}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
日期
这用于将输入字符串转换为日期格式。
句法
Propertyvalue | date:”dateformat”
参量
dateformat-这是输入字符串应转换为的日期格式。
结果
该属性值将转换为日期格式。
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
newdate = new Date(2016, 3, 15);
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The date of this Tutorial is {{newdate | date:"MM/dd/yy"}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
货币
这用于将输入字符串转换为货币格式。
句法
Propertyvalue | currency
参量
没有。
结果
属性值将转换为货币格式。
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
newValue: number = 123;
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The currency of this Tutorial is {{newValue | currency}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
百分比
这用于将输入字符串转换为百分比格式。
句法
Propertyvalue | percent
参量
没有
结果
该属性值将转换为百分比格式。
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
newValue: number = 30;
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The percentage is {{newValue | percent}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
百分比管道还有另一种变化,如下所示。
句法
Propertyvalue | percent: ‘{minIntegerDigits}.{minFractionDigits}{maxFractionDigits}’
参量
- minIntegerDigits-这是最小整数位数。
- minFractionDigits-这是最小的小数位数。
- maxFractionDigits-这是小数位数的最大数目。
结果
属性值将转换为百分比格式
例
首先,确保以下代码存在于app.component.ts文件中。
import {
Component
} from '@angular/core';
@Component ({
selector: 'my-app',
templateUrl: 'app/app.component.html'
})
export class AppComponent {
newValue: number = 0.3;
}
接下来,确保在app / app.component.html文件中存在以下代码。
<div>
The percentage is {{newValue | percent:'2.2-5'}}<br>
</div>
输出量
保存所有代码更改并刷新浏览器后,您将获得以下输出。
猜你喜欢
- 2024-11-14 angular8 ui-grid升级方案 angular8升级angular10
- 2024-11-14 angular8 日常开发避坑指南(30个)
- 2024-11-14 Angular 11.1.0-next.2 发布 angular 11发布的影响
- 2024-11-14 最近写Vue,真是累死人了!没有Angular爽,谁能帮帮我?[吐槽]
- 2024-11-14 「Angular项目实战」Angular2+如何去除URL中的#号
- 2024-11-14 Angular9构建一个后台管理系统(二)
- 2024-11-14 AngularJs入门,一个简单的demo angular实战
- 2024-11-14 Angular1升级到Angular2之组件样式封装
- 2024-11-14 逆袭之路系列-AngularJS 1.2版本编程入门-01
- 2024-11-14 Angular9构建一个后台管理系统(一)
- 06-18单例模式谁都会,破坏单例模式听说过吗?
- 06-18Objective-c单例模式的正确写法「藏」
- 06-18单例模式介绍(单例模式都有哪些)
- 06-18前端设计-单例模式在实战中的应用技巧
- 06-18PHP之单例模式(php单例模式连接数据库)
- 06-18设计模式:单例模式及C及C++实现示例
- 06-18python的单例模式(单例 python)
- 06-18你认为最简单的单例模式,东西还挺多
- 最近发表
- 标签列表
-
- jsp (69)
- gitpush (78)
- gitreset (66)
- python字典 (67)
- dockercp (63)
- gitclone命令 (63)
- dockersave (62)
- linux命令大全 (65)
- pythonif (86)
- location.href (69)
- dockerexec (65)
- tail-f (79)
- queryselectorall (63)
- location.search (79)
- bootstrap教程 (74)
- 单例 (62)
- linuxgzip (68)
- 字符串连接 (73)
- html标签 (69)
- c++初始化列表 (64)
- mysqlinnodbmyisam区别 (63)
- arraylistadd (66)
- mysqldatesub函数 (63)
- window10java环境变量设置 (66)
- c++虚函数和纯虚函数的区别 (66)