angularjs - Angular: a better way to filter when you're only expecting one result -


i'm using following angular code 1 item out of list.

<span ng-repeat="metro in metros | filter:{id:event.metro_id}">     {{metro.timezone}} </span> 

so there's list of metros , i'm filtering list metros id matches event.metro_id. thing is, scenario know there's going 1, , 1, match filter , feels silly use ng-repeat 1 element. there more elegant way this. goal in html template , avoid placing more code in angular controller.

if modify metros structure (only in favour of want to), collection id's properties, in html:

<span ng-show="event.metro_id">     {{metros[event.metro_id].timezone}} </span> 

i meant have metros this:

$scope.metros = {   "25" : {     "timezone" : 25,     "foo" : "bar"   },   "35" : {     "timezone" : 35,     "foo" : "bar"   } } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -