0

I have a problem! I do not understand how I can make a condition - in a template - I do not need to print an item if array have item with key - "HIS" and length more than one. In other words, if the array includes only NIS (without other currencies) should not be shown... I think it should work like hasOwnProperty of object, right?

var currencies = {
 "NIS": {
    "income": 12,
    "received" : 13
  },
  "USD" : {
     "income": 122,
     "received" : 113,
     "nisCourse" : 3,4
   }
};

and view of it thought ng-reapet

<div class="income_total_row"
     ng-repeat-start="(key, value) in currencies track by $index"
     ng-if="value.income != 0">
     {{ value.income }}
</div>

<div class="income_total_row" ng-if="key !== 'NIS' && value.income != 0"
     ng-repeat-end="">
         {{ value.nisCourse }}
</div>

I tried to explain (

georgeawg
  • 48,608
  • 13
  • 72
  • 95
Inky Rein
  • 47
  • 6
  • `HIS` or `NIS`? – lealceldeiro Jul 23 '18 at 16:52
  • @lealceldeiro, NIS, It is mistake during editing. – Inky Rein Jul 23 '18 at 17:00
  • Possible duplicate of [Angular.js ng-repeat filter by property having one of multiple values (OR of values)](https://stackoverflow.com/questions/21987904/angular-js-ng-repeat-filter-by-property-having-one-of-multiple-values-or-of-val) – BShaps Jul 23 '18 at 17:23
  • @Inky Rein, I should have clarified about this in my previous comment. You are not iterating over an array but over an object (`currencies`), secondly... just to be clear... you want to show the repeat if the object has more than one currency or if it has only one item different from `NIS`... is that right? – lealceldeiro Jul 23 '18 at 17:23
  • For your use case, you should be using just `ng-repeat` instead of `ng-repeat-start` and `ng-repeat-end`. Also take the `ng-if` off of your `ng-repeat` div and nest another div inside of your repeat with the `ng-if` – BShaps Jul 23 '18 at 17:23
  • Refer this https://stackoverflow.com/questions/14788652/how-to-filter-key-value-with-ng-repeat-in-angularjs – Aravinthan K Jul 23 '18 at 17:24
  • `"nisCourse" : 3,4` looks sketchy. – georgeawg Jul 23 '18 at 17:28
  • @lealceldeiro, yes, probably you right - it is object - one of the proposed solutions - through a filter give me the error Error: [filter:notarray] Expected array but received: {"USD": "nisCourse":"3.6470", "income":21,"received":0}, "NIS":{"nisCourse":"1","income":12,"received":66}} . – Inky Rein Jul 23 '18 at 18:09
  • @lealceldeiro if the array includes only NIS (without other currencies) should not be shown - if NIS in array with other currensies - shows all items of arrays – Inky Rein Jul 23 '18 at 18:14
  • @BShaps - thanks for advice - I rewrite my structure - i have div with ng-repeat, and incide it anathe div with ng-if. And create filter function, but it gives me error Error: [filter:notarray] ... as I try give it object? – Inky Rein Jul 23 '18 at 18:17

0 Answers0