【发布时间】:2016-03-12 18:04:01
【问题描述】:
我想创建一个返回 json 的服务
或者通过对服务器的请求,或者通过检查它是否已经存在于:Window.content
但我不想从我的控制器那里得到承诺!
我要准备好 json!
我已经尝试过好几次了
我尝试使用 then 方法在我的服务中进行测试
但我仍然得到一个承诺
(是否只带$http,是否带$q)
如果没有得到控制器的承诺,我无法获得价值
我的服务:
app.service('getContent',['$http', function( $http ){
return function(url){ // Getting utl
if(window.content){ // if it's the first loading, then there is a content here
var temp = window.content;
window.content = undefined;
return temp;
}
return $http.get(url);
};
}]);
我的控制器:
.state('pages', {
url: '/:page',
templateProvider:['$templateRequest',
function($templateRequest){
return $templateRequest(BASE_URL + 'assets/angularTemplates/pages.html');
}],
controller: function($scope, $stateParams, getContent){
// Here I want to to get a json ready :
$scope.contentPage = getContent(BASE_URL + $stateParams.page + '?angular=pageName');
}
});
【问题讨论】:
标签: angularjs angular-promise angular-services