Getting first row of a type in ngFor of Angular 2

Discussão em 'Angular' iniciado por Luckyy, Novembro 8, 2024.

  1. Luckyy

    Luckyy Guest

    So, I have data like (Angular 2):

    [
    {text: "first", name: "a"},
    {text: "rw", name: "a"},
    {text: "ds", name: "b"},
    {text: "asdf", name: "b"},
    {text: "ASDF", name: "b"},
    {text: "ertre", name: "b"}
    {text: "hf", name: "c"}
    ]


    I have to use that data to show the list of the content, but in the way like

    <div>a</div>
    <p>a's text 1</p>
    <p>a's text 2</p>
    <p>a's text 3</p>
    <div>b</div>
    <p>b's text 1</p>
    <p>b's text 2</p>
    <p>b's text 3</p>


    Is this possible without creating custom filters? Means simply, if else in ng repeat *ngFor.

    Basically I would do ngIf to show header div if its first occurance for that value (we can check if a==a then hide header, b==a then show header).

    Continue reading...

Compartilhe esta Página