Angular 4 引入了新的“titlecase”管道“|”并用于将每个单词的第一个字母更改为大写。
示例如下:
<h2>{{ 'ramesh rajendran` | titlecase }}</h2>
<!-- OUTPUT - It will display 'Ramesh Rajendran' -->
在打字稿代码中可能吗?如何?
是的,在 TypeScript 代码中是可能的。您需要致电管道transform()
方法。
您的模板:
<h2>{{ fullName }}</h2>
在你的 .ts 中:
import { TitleCasePipe } from '@angular/common';
export class App {
fullName: string = 'ramesh rajendran';
constructor(private titlecasePipe:TitleCasePipe ) { }
transformName(){
this.fullName = this.titlecasePipe.transform(this.fullName);
}
}
你需要添加TitleCasePipe
在您的 AppModule 提供程序中。您可以在单击按钮或打字稿代码中的某些其他事件时调用转换。
这是一个链接笨蛋演示 https://plnkr.co/edit/zuqdWDkMDXF5U92ZYB9E?p=preview
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)