微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

角度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链接

原文地址:https://www.jb51.cc/angularjs/141412.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐