De_Viator
De_Viator

Reputation: 11

How I can get definite value in keyvalue pair?

My object has a specific set of key / value pairs, i want to get a specific value, not everything, how can i do this?

For example:

.ts

movie = {
     title:'title',
     description:'descriprtion',
     rating:4

    };

html:

<ul *ngFor="let item of movie | keyvalue">
    <li> {{item.value}} </li>
</ul>

And I only want to receive item.description, can you tell me how this can be implemented?

Upvotes: 0

Views: 42

Answers (1)

danday74
danday74

Reputation: 56956

    <ul *ngFor="let item of movie | keyvalue">
      <ng-container *ngIf="item.key === 'description'">
        <li>{{item.value}}</li>
      </ng-container>
    </ul>

But to be honest you would be better off just doing:

    <div>{{ move.description }}</div>

Since you do not seem to want to iterate the object props, but only want description.

Upvotes: 1

Related Questions