我是angular.js的新手
在我的角度运行方法中,服务器端有api请求,并且在angular.constant中分配了接收数据
angular.constant在我的指令中使用,该指令在我的html页面中使用。
当我的应用程序运行时一切正常但问题是当重新加载应用程序时,html页面和run方法的api调用同时执行。所以问题是首先调用我的html页面指令,然后从服务器接收数据。所以在该指令中,angular.constant值为null,并且由于angular.constant的null值,指令行为不正确
在html DOM渲染后数据是否来自服务器端有什么解决方案吗?
提前谢谢。答案 0 :(得分:1)
像
这样的东西angular.module('MyApp', [])
.controller('myController', function ($scope, $html) {
$http.get('/some-url')
.success(function (data) {
// Do whatever you need to do with `data`
});
});
这应首先加载控制器,然后拨打/some-url
data
的电话。
答案 1 :(得分:0)