![](/img/trans.png)
[英]ionic3 how can i inject service/provider inside ErrorHandlerService
[英]ionic3 - how can i remove the text in the ngFor component
我使用NgFor生成组件,但是按钮中的一些文本需要删除。 例如,数组中的文本为RCDD06。但是我想将其显示为06,而数组中的数据未更改。我停留在这里大约4小时
这是数组:
[{"name":"RCDD01"},{"name":"RCDD02"},{"name":"RCDD03"},{"name":"RCDD04"},{"name":"RCDD05"},{"name":"RCDD06"}]
这是html中的代码:
<button ion-button *ngFor="let item of device" (click)="getData(item.name)">{{item.name}}</button>
创建一个自定义管道并通过字符串replace()方法更改文本
HTML
<button ion-button *ngFor="let item of device" (click)="getData(item.name)">{{item.name | remChar}}</button>
pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'remChar'
})
export class RemCharPipe implements PipeTransform {
transform(value: any): any {
return value.replace(/[a-z]|[A-Z]/g, "");
}
}
在app.module.ts文件的声明中导入管道
参考演示链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.