0

Is possible to iterating over objects and check their property ?

{
 Obj1 : { visible : true, value : 2}
 Obj2 : { visible : false, value : 4}
 Obj3 : { visible : true, value : 6}
}

HTML:

<ul ng-show="data.templates.attachments">
        <li ng-repeat="(key, value) in data.templates.attachments | filter :       value.visible">{{key}}</li>
</ul>

If I would like to show only key it is perfect, but I would like to hide these invisibles.

2 Answers 2

3

Try this

<li ng-repeat="(key, value) in data | filter: {visible: true}">{{value.value}}</li>

Example

Update:

Filter by object property in object

// only for one property, for example {a: 1}
myApp.filter('filterByProperty', function () {
  return function(items, field) {
      var result = {},
          key    = Object.keys(field).pop(),
          value  = field[key];

      angular.forEach(items, function(el, index) {
          if (el[key] === value) {
              result[index] = el;
          }
      });

      return result;
  };
});

Example

Sign up to request clarification or add additional context in comments.

2 Comments

@InnerWorld you can write your own filter like this jsfiddle.net/HB7LU/10336
I need to understand them little more, but yes - it is what I would have. Thank you.
0

Alexander has already answered the question, but if you still want to keep the element for each object in the dom and just want it not to be shown (the visible property in your object makes an impression that it might just not be shown, instead of not being inserted into dom),

then you might do this using ng-class http://jsfiddle.net/naeemshaikh27/dKjz5/48/

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.