1

I have a JSON in the following format:

{
    key: value,
    key: value,
    key: {
       key: value,
       key: value
    }
}

I want to print these key values out to my page using Angular's ngIf to identify if the value is a string or another object. I tried using typeof but it gives me an unresolved variable error in Webstorm.

How do I know that the value is an object and that I need to go in and take key values from in there?

I am using Angular 6 & Webstorm IDE.

1 Answer 1

1

You can create a function to get that value.Take a look at this demo

In component.ts:

checkType(data){
  return typeof(data)
}

In html:

<div *ngIf="checkType(data.k1) === 'string'">
  I am string
</div>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.