角度4的标题管
发布时间:2020-12-17 08:20:25 所属栏目:安全 来源:网络整理
导读: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' -- 打字稿代码有可能吗?
例如, <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的链接 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |