我是角度ui路由器的新手.
我从本地.json文件加载设置时遇到问题.
我将设置保存在$ rootscope.settings中的app.run()上.
.run(['$rootScope', '$http', '$state', '$stateParams', function ($rootScope, $http, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
$http.get('./App/Core/Config/config.json').success(function (data) {
$rootScope.settings = data;
});
}])
Run Code Online (Sandbox Code Playgroud)
在我进入$ state之前,我需要来自$ rootscope.settings的设置来获取数据.但在解决方案中,$ rootscope.settings是未定义的.
.state('alertcenter', {
url: '',
views: {
'alertcenter': {
templateUrl: './App/Features/AlertCenter.html',
controller: 'AlertCenter'
}
},
resolve: {
Data: ['$http', function ($http) {
return $http({
method: 'GET',
url: $rootScope.settings.baseUrl + '/getData',
withCredentials: true
});
}]
}
});
Run Code Online (Sandbox Code Playgroud)
如何在解决$ state时访问设置?还是有另一种更好的方法吗?
resolve: {
Data: ['$http','$rootScope', function ($http, $rootScope) {
return $http({
method: 'GET',
url: $rootScope.settings.baseUrl + '/getData',
withCredentials: true
});
}]
}
Run Code Online (Sandbox Code Playgroud)
尝试首先将$ rootScope注入解析函数.
| 归档时间: |
|
| 查看次数: |
7885 次 |
| 最近记录: |