javascript - Get Object based on Key Value in Angular ui-router state params -
i trying retrieve object in firebase based on 1 of objects key values in ui-router $stateparams. example:
firebase structure:
"businesses" : { "-kp_xebaya8oln6wousx" : { "category" : "restaurant", "link" : "urlfriendly", "name" : "some restaurant" },
the link page so:
website.com/food/restaurants/urlfriendly
in app.js:
.state('food.restaurants.item',{ url: '/:item', templateurl: function($stateparams){ return 'pages/business.html' }, controller: function($scope, $firebasearray $stateparams){ var sref = firebase.database().ref().child("businesses"); $scope.restarants = $firebasearray(sref); var matches = $scope.restaurants.filter(function(val, index, array){ return val.link === $stateparams.item; }); $scope.finalitem = matches[0]; } })
the end result $scope.finalitem
loaded 1 of objects like:
<h2>{{finalitem.name}}</h2>
Comments
Post a Comment