1

currently i'm developing a webpage using angular - i have a class with 2 items as below:

Array(2)
 0: uiData { id: 12, price: 324 }
 1: uiData { id: 23, price: 432 }

i'm trying to access these data in angular template

<div *ngFor="let item of uiData">
    price: {{item.price}}
</div>

output:what i getting is as below

price: 324
price: 432

desired output i'm looking for is

price: 324/432

tried accessing the data by providing the index , like uiData[0].price/uiData[1].price but this isn't working.

is there a way to access these items?

2
  • 1
    What's the error in using: uiData[0].price/uiData[1].price? Commented Nov 4, 2021 at 7:04
  • The entire applications data points are zero, meaning displaying zeros. Commented Nov 4, 2021 at 8:53

2 Answers 2

1

you should be able to access these data by reopen another {{}}

<div>
    price: {{uiData[0].price}}/{{uiData[1].price}}
</div>

If you don't want to access directly the data at range 0 and 1 you can also loop on array like that

<div>
    price: 
    <span *ngFor="let item of uiData;last as isLast">
      {{item.price}}
      <ng-container *ngIf="!isLast">/</ng-container>
   </span
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

you have a duplicate "
@jeremy-denis: Thanks for the solution , the second option looping through the array solved my problem. The first option is displaying zero's in the entire application.
0

You can write something like this:

<div> price: <span *ngFor="let item of uiData;index as i">
    {{item.price}}
        <span *ngIf="i!=(uiData?.length-1)">/
        </span>
    </span>
</div>

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.