Angular JS-ng-iteration & filter-comparator is not an exact match to query string value?

I have several dynamic pages that follow the query string pattern:

"...com/directory/my-post-title?id=#"

      

where hash is a digit defined in the JSON file assigned when created.

No problem with routing, etc, and I was successfully able to use this with ng-repeat to fetch data when there is no exact match, but for some reason it doesn't work as expected when applied.

In the following setup, I use a function inside my filter to pull the query string from the url, which is then used to set the filter. Any reason this doesn't work?

Template:

<div data-ng-repeat="item in items | filter:{itemID:queryID}:true | limitTo:'1'">
   {{::item.name}}
</div> 

      

Controller:

angular.module('myApp').controller('mainCtrl', ['$rootScope', '$scope', '$location', function($rootScope, $scope, $location) {
   $rootScope.$on('$routeChangeSuccess', function(event, current, previous) {
      $scope.queryID = $location.search().id;
   });
}]);

      

JSON:

{
"myItems": [
    {
      "itemID": 1,
      "name": "some name"
   },
   {
      "itemID": 11,
      "name": "another name"
   }
]
}

      

+3


source to share





All Articles