AngularJS在JSON get后等待视图
AngularJS wait view after JSON get
首先抱歉我的英语不好。我有一个关于angularjs的问题。与此http post请求,我得到相同的数据从mysql json格式。
app.controller('DeviceActivityCtrl', function ($scope, $rootScope, $location, $http, Data,$stateParams,DeviceActivityResult) {
//$scope.foodDistribution=null;
if (DeviceActivityResult.status == "success") {
$scope.deviceActivityLog = DeviceActivityResult;
$scope.authError = 'Correct';
alert(DeviceActivityResult.data[0].steps);
}
else {
$scope.authError = 'notsuccess';
}
});
问题在这里。当视图(html)被加载时,如果http请求没有完成。加载html失败。因为百分比:数据(未准备好)。我如何能等待加载视图(html)的json得到完成它的工作。谢谢你的帮助
<div class="inline">
<div ui-jq="easyPieChart" ui-options="{
percent: ({{deviceActivityLog.data[0].activity_time}}/340)*100,
lineWidth: 10,
trackColor: '{{app.color.light}}',
barColor: '{{app.color.success}}',
scaleColor: '{{app.color.light}}',
size: 188,
lineCap: 'butt'
}">
<div>
<span class="h2 m-l-sm step">{{(deviceActivityLog.data[0].activity_time/340)*100|number:0}}</span>%
<div class="text text-sm"></div>
</div>
</div>
</div>
---------------- 状态 ---------------
.state('report.food', {
url: '/{userid:[0-9]{1,4}}',
templateUrl: 'tpl/report_food.html',
controller: 'DeviceActivityCtrl',
resolve: {
deps: ['$ocLazyLoad',
function ($ocLazyLoad) {
return $ocLazyLoad.load('ui.grid').then(
function () {
return $ocLazyLoad.load('js/app/report/reportFood.js','UiGridDemoCtrl.resolve');
}
);
},
],
DeviceActivityResult: function(Data, $stateParams) {
return Data.post('deviceActivity',
{userid: $stateParams.userid}
);
}
}
})
看起来你正在使用ui-router,所以你可以在转换到它之前'解析'状态数据。下面是一个示例:
.state('yourState', {
...
controller: 'DeviceActivityCtrl',
resolve: {
DeviceActivityResult: function(Data, $stateParams) {
return Data.post('deviceActivity',
{userid:$stateParams.userid}
);
}
}
})
.controller('DeviceActivityCtrl', function ($scope, $rootScope, $location, $http, DeviceActivityResult) {
// Data.toast(DeviceActivityResult);
if (DeviceActivityResult.status == "success") {
$scope.deviceActivityLog = DeviceActivityResult;
$scope.authError = 'Correct';
}
else {
$scope.authError = 'notsuccess';
}
});
相关文章:
- 如何使用javascript从主svg对象动态创建svg视图框
- 正在使用$location.path(.)路由ng视图
- angular.js没有'无法在PhoneGap中处理视图标记
- 如何包含特定于每个视图angularjs的javascript文件
- 单击按钮以等待单击按钮
- React组件等待所需道具进行渲染
- 通过在Dojo mobile ViewController.openExternalView中动态更改打开同一外部视图的
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- Ajax Live搜索发布到Laravel视图
- backbone.js无法渲染视图
- 根据某些条件在视图之间切换
- 挖空.js:等待视图模型实例化完成
- 在呈现子视图之前等待集合数据
- 如何在backbone.js中等待渲染视图,直到获取完成
- 如何在react.js中等待渲染视图直到$.get()完成
- AngularJS在JSON get后等待视图
- AngularJS-等待加载数据以显示视图
- 在Backbone.js视图中等待“无限滚动”结果
- 在等待承诺的同时切换 AngularJS 视图
- AngularJS视图不会等待$http.get