[英]ionic3 - how can i remove the text in the ngFor component
I use NgFor to generate the component but some text in the button need to remove. 我使用NgFor生成组件,但是按钮中的一些文本需要删除。 For example,the text in the array is RCDD06.But i want to display it as 06 and the data in the array is unchanged.I have stuck in here about 4hours
例如,数组中的文本为RCDD06。但是我想将其显示为06,而数组中的数据未更改。我停留在这里大约4小时
Here is the array: 这是数组:
[{"name":"RCDD01"},{"name":"RCDD02"},{"name":"RCDD03"},{"name":"RCDD04"},{"name":"RCDD05"},{"name":"RCDD06"}]
Here is the code in the html: 这是html中的代码:
<button ion-button *ngFor="let item of device" (click)="getData(item.name)">{{item.name}}</button>
create an custom pipe and change the text by string replace() method 创建一个自定义管道并通过字符串replace()方法更改文本
html HTML
<button ion-button *ngFor="let item of device" (click)="getData(item.name)">{{item.name | remChar}}</button>
pipe.ts 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, "");
}
}
import your pipe in declarations of your app.module.ts file 在app.module.ts文件的声明中导入管道
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.