1

How do I retrieve only the first word , in this case "Koobiyo" from angular html?

json object:

{
    "otherInformation": "Koombiyo,Kurunegala,Kuliyapitiya"
}

I want to access from it here, like this?

HTML:

<td>
    {{ issue.otherInformation }}
</td>

how do I do that?

1 Answer 1

2

You can create a simple pipe,

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(" ");
  }
}

and use it as,

{{issue.otherInformation | sliceWords:0:1}}

Stackblitz Demo

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.