将 $resource 请求放入 Controller 函数时出现问题。它直接从控制器工作,但不在函数内部。
也许有人知道为什么?谢谢!
angular.module('Vote', ['ngResource']);
function VotesController($scope, $resource) {
$scope.simple = $resource('url'); // works
$scope.some_item = $scope.simple.get();
$scope.upvoteQuestion = function($scope, $resource) {
$scope.simple = $resource('url'); // gets error: undefined
$scope.some_item = $scope.simple.get();
}
}