1

I have this JSON file that I used $http() to get. It is something like this:

[ {
    "sno": "3",
  "eventname": "hockey",
  "event-type": "sports",
  "A-team": "mme",
  "B-team": "eee",
  "Gender": "male",
  "time": "2017-11-24 00:00:00",
  "isresult": "0",
  "result": "",
  "match-type": "semi",
  "venue": "downs"
}]

I need to display item.result as N/A if item.isresult==0 and a string if item.isresult==1. How do I do that?

8
  • You can use ng-if. <p ng-if='item.isresult === '1''>{{item.result}}</p> Commented Nov 23, 2017 at 6:24
  • you can use filter Commented Nov 23, 2017 at 6:25
  • filter is not doing it Commented Nov 23, 2017 at 6:26
  • @SatyamRaj post your code. Commented Nov 23, 2017 at 6:26
  • jsfiddle.net/w55pehyg Commented Nov 23, 2017 at 6:28

3 Answers 3

1

Use ng-if

<div ng-if="item[0].isresult ==='0'">
Sign up to request clarification or add additional context in comments.

Comments

0

Use ng-show

<div ng-show="item[0].isresult ==='0'">

Comments

0

Say your list is named "items -

<div ng-repeat="item in items track by $index">
    <div ng-show="item.isresult === '0'"> N/A </div>
    <div ng-hide="!item.isresult === '0'"> {{stringToBeDisplayed}} </div>
</div>

I'm guessing your string is a variable you're storing. I'd also suggest you use boolean values for item.isresult instead of strings or numbers to avoid possible errors.

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.