我有几个动态页面遵循简单的查询字符串模式:
"...com/directory/my-post-title?id=#"
其中hash是在创建时分配的JSON文件中定义的数字。
路由等没有问题,我已经成功地使用ng-repeat来检索数据,当精确匹配比较器不存在时,但由于某些原因它在应用时不能按预期工作。 / p>
在下面的设置中,我在我的过滤器中使用一个函数从url中提取查询字符串,然后用于设置过滤器。有什么原因导致这种情况无效吗?
模板:
<div data-ng-repeat="item in items | filter:{itemID:queryID}:true | limitTo:'1'">
{{::item.name}}
</div>
控制器:
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"
}
]
}