gpt4 book ai didi

angular - 有谁知道如何在 component.ts 文件中使用 titlecase 而不是在 html 文件中?

转载 作者:行者123 更新时间:2023-12-01 21:42:14 25 4
gpt4 key购买 nike

我尝试了以下代码,但它不起作用。

import { Component } from '@angular/core';
import { TitleCasePipe } from '@angular/common';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
title = 'Working with Pipe';
testValue = this.titleCasePipe.transform('firstletter should be upper case.');


constructor(
public titleCasePipe: TitleCasePipe
){}

}

enter image description here

最佳答案

在组件元数据的 providers 数组中添加 TitleCasePipe :

@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ],
providers: [TitleCasePipe]
})

Stackblitz example

关于angular - 有谁知道如何在 component.ts 文件中使用 titlecase 而不是在 html 文件中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61206429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com