【发布时间】:2015-05-11 16:54:27
【问题描述】:
我正在使用 AngularJS 设置一个表格并通过搜索或类别关键字过滤其数据。我
AngularJS
categorieFilter = angular.module("categorieFilter", [])
categorieFilter.controller("catFilter", ["$scope", "store", function($scope, store){
$scope.search = "";
$scope.products = [];
$scope.categories = [];
$scope.categories = store.getCategories();
$scope.products = store.getProducts();
$scope.filterProductsByCats = function(category){
$scope.search = category;
};
}])
categorieFilter.factory('store', function($http){
return {
getCategories: $http.get('api/categories').success(function (data) {
return data;
}),
getProducts : $http.get('api/products').success(function (data) {
return data;
}
};
});
$http.get 本身正在工作,当我直接浏览到我的 api 时,我得到了所需的数据。此外,当我在类别中的 $hhtp.get 之后执行警报(数据)时,我得到了我需要的数据......所以这应该有效,但它没有。我收到一个错误:
TypeError: store.getCategories 不是函数
我不知道这是从哪里来的。有人解决这个问题吗?
【问题讨论】:
标签: javascript angularjs