0
我的RootCtrl中有一个方法可以调用我的http api,并返回结果。
$scope.checkAccess = function(){
var result = MyService.me();
result.then(function(response){
console.log(response);
if (response.data != 'false'){
return true;
}
else{
return false;
}
});
}
但是当我尝试调用此方法在儿童控制器之一,像这样......
var access = $scope.checkAccess();
它告诉我access
是不确定的。
我在这里做错了什么?
这是服务调用的样子。
me: function() {
return $http({
url: 'http://localhost:5000/api/me',
method: 'GET'
});
}
@OP,然而要注意'access'将包含一个承诺对象,而不是价值。你将不得不使用..'.then()'与回调来获得布尔值。 – 2014-10-30 18:44:42