我有一个休息后端服务,我用来加载一些数据,在角度方面,我想用它在UI中显示标签,所以在主控制器我使用这样:
$scope.checkTabAvailable = function () {
getEPJFeatures().then(function (features) {
$log.info("available features length in checkpoint.." + features.length);
});
return true;
}
var listFeatures=[];
function getEPJFeatures() {
var d = $q.defer();
if (listFeatures) {
d.resolve(listFeatures);
}
else {
$http.get(urlService.restClientUrl("available_features"))
.success(function (data) {
$log.info("available features length.." + data.length);
listFeatures = data;
d.resolve(listFeatures);
})
.error(function (error) {
$log.error("Error while loading features: " + error);
d.reject(error);
});
}
return d.promise;
}
这是一个html:
<ul class="items">
<li data-ng-show="checkTabAvailable()" >
<a href="#/tv">tv</a>
</li>
<li data-ng-show="checkTabAvailable()">
<a href="#/Radio">Radio</a>
</li>
<li data-ng-show="checkTabAvailable()">
<a href="#/extraF">extraF</a>
</li>
因为这会产生许多承诺,所以会收到错误:
Error: $rootScope:infdig
Infinite $digest Loop
有没有更好的方法加载一次restEnd调用,然后在html端重用?