如何只检索第一个单词,在本例中是“Koobiyo”?JSON对象:
{ "otherInformation": "Koombiyo,Kurunegala,Kuliyapitiya" }
我想从这里进入,像这样?超文本:
<td> {{ issue.otherInformation }} </td>
我该怎么做呢?
k10s72fa1#
可以创建简单的管道,
import { Pipe, PipeTransform } from "@angular/core"; @Pipe({ name: "sliceWords" }) export class SliceWordsPipe implements PipeTransform { transform(value: string, start: number, end?: number): string { if (value == null) return null; return value .split(",") .splice(start, end) .join(" "); } }
并将其用作,
{{issue.otherInformation | sliceWords:0:1}}
Stackblitz Demo
1条答案
按热度按时间k10s72fa1#
可以创建简单的管道,
并将其用作,
Stackblitz Demo