For my AngularJS project (v1.2.3), I have a list of routes and am trying to build a navigation bar from the object. What I want to do is display any object with an undefined isRight
property in one style, and where the property is defined in another.
In one ng-repeat
I would like to filter those objects with an undefined isRight
property. How can I accomplish this inside the ng-repeat
attribute, without having to resort to creating a custom filter function?
$scope.nav = [
{ path: '/', title: 'Home' },
{ path: '/blog', title: 'Blog' },
{ path: '/about', title: 'About' },
{ path: '/login', title: 'Login', isRight: true }
];
I realize I could just add the attribute isRight: false
to each object, or have separate nav objects for right and left side links, and other such simple workarounds, but I am curious if there is a way to accomplish this with the current structure, using something along the lines of:
<li ng-repeat="link in nav | filter:{isRight:undefined}">
This is more a curiosity than a need, but I appreciate any suggestions.
prop: undefined
to filter for when the property didn't have a value, andprop: {}
for when the property was an object. The problem is that neither of these included when the property was missing. Thanks for asking this question that helped me find the magic!
and!!
!