我是 AngularJS 的新手。我正在尝试过滤recipe
由recipeService
. 我的对象出现,但没有应用过滤器。
如果我将项目直接附加到my中$scope
调用的变量,而不是使用,则过滤器将起作用。recipes
controller.js
ng-repeat="recipe in recipes"
有什么建议吗?问候。
HTML
<li ng-repeat="recipe in recipeService.allRecipes | orderBy:'name':reverse">{{recipe.name}}</li>
我工厂的reciperService.service.js:
var service = {};
service.allRecipes = [];
service.getAllRecipes = function () {
return $http.get('/api/recipes')
.success(function (recipes) {
service.allRecipes = recipes;
return recipes;
});
};
return service;
控制器声明中的controller.js:
$scope.recipeService = recipeService;
recipeService.getAllRecipes();