角度4的标题管

Angular 4 introduced a new ‘titlecase’ pipe ‘|’ and use to changes the first letter of each word into the uppercase.

例如,

<h2>{{ 'ramesh rajendran` | titlecase }}</h2>
<!-- OUTPUT - It will display 'Ramesh Rajendran' -->

打字稿代码有可能吗?如何?

是的,可以在TypeScript代码中使用.您需要调用Pipe的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);
    }
}

您需要在AppModule提供程序中添加TitleCasePipe.您可以通过按钮单击或打字稿代码中的其他事件来调用转换.

这是PLUNKER DEMO链接

相关文章

ANGULAR.JS:NG-SELECTANDNG-OPTIONSPS:其实看英文文档比看中...
AngularJS中使用Chart.js制折线图与饼图实例  Chart.js 是...
IE浏览器兼容性后续前言 继续尝试解决IE浏览器兼容性问题,...
Angular实现下拉菜单多选写这篇文章时,引用文章地址如下:h...
在AngularJS应用中集成科大讯飞语音输入功能前言 根据项目...
Angular数据更新不及时问题探讨前言 在修复控制角标正确变...