![](/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.