2014-04-01 56 views
0

我得到以下错误:

TypeError: Cannot call method 'then' of undefined 

这个代码:

App.controller('MainCtrl', ['$scope', 'Main', 'MainFilter', function($scope, Main, MainFilter) { 
    $scope.scope_variable = Main.query().$promise.then(function(result) { MainFilter.do_something(result) }); 
}]); 

App.factory('Main', ['$resource', function($resource) { 
    return $resource('/main_resource.json') 
}]); 

我一直努力遵循使用控制器内承诺的这些其他例子(我没有使用$ routeProvider),但似乎没有任何工作。

AngularJS using $resource service. Promise is not resolved by GET request

AngularJS resource promise

+0

你在哪里定义'$ promise'? –

+0

'Main.query({},function(data){console.log(data)})' – tymeJV

+0

我假定$ promise被定义在$ resource中... –

回答

0

@tymeJV提供这样的回答:

$ scope.scope_variable = Main.query({},功能(结果){MainFilter.do_something(结果)});

+0

@tymeJV,如果您提供答案,我会将其标记为已接受 –