,我有一些可以更改单词的项目
示例:lang->语言
我想让离子选项显示所有物品在大写
中的第一个字母示例:作者 ->作者
示例
author Author
lang Language
date Date
loca Location
mycode
<ion-select [(ngModel)]="refine" (ionChange)="optionsFn(item, i);" >
<ion-option [value]="item" *ngFor="let item of totalfilter | mypipe;let i = index" >{{item["@NAME"]}}</ion-option>
</ion-select>
mypipe.ts
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mypipe', pure: false
})
export class MyPipe implements PipeTransform {
public posts;
public post;
transform(items: any[]): any[] {
if (items && items.length)
this.posts = items.filter(it => it["@NAME"] = it["@NAME"].replace('lang','language'));
this.post = this.posts.filter(it => it["@NAME"] = it["@NAME"].charAt(0).toUpperCase()+ it["@NAME"].slice(1))
return this.post;
}
}
不起作用,错误是
无法读取未定义的属性'过滤器
执行此操作:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'mypipe', pure: false
})
export class MyPipe implements PipeTransform {
transform(items: any[]): any[] {
if (items && items.length)
return items.filter(it => it["@NAME"] = it["@NAME"].charAt(0).toUpperCase() + it["@NAME"].slice(1));
return items;
}
}