Reputation: 15732
I am using in my HTML:
<div ng-repeat="item in items" ng-show="!$last">
<div>{{ item.value }}</div>
</div>
..to hide the last element of a mongodb document (aka JSON data). All other elements of the JSON data gets printed out as expected.
Now how can I hide the last two members of my json data, or alternatively hide by key name, e.g. "__v" and "_id" should be hidden from the user.
Upvotes: 1
Views: 2058
Reputation: 11547
You could write a custom filter to return all the keys of an object but excluding the ones that you don't want, e.g. keys with _
prefix.
app.filter('keys', function () {
return function (obj) {
return Object.keys(obj).filter(function (k) {
return k && k.charAt(0) !== '_' && k !== '$$hashKey';
});
};
});
and use it in ng-repeat
like this:
<ul>
<li ng-repeat="friend in friends">
<input type="text" ng-repeat="key in friend | keys" ng-model="friend[key]" />
</li>
</ul>
Example Plunker: http://plnkr.co/edit/ws5RqR5zN71ZHY7OCxtD?p=preview
Upvotes: 1