我想在下面概括我的状态代码以传入一个字符串作为load的参数,该参数将被称为模块,然后在加载调用中解析延迟加载。简单地添加一个字符串会出错,因为Angular认为它是一个提供者并触发一个未知的提供者异常。
我怎样才能实现这个目标?
function load ($ocLazyLoad, $q, $stateParams, module){
var deferred = $q.defer();
try{
$ocLazyLoad.load(module).then(function(){
deferred.resolve();
});
}
catch (ex){
deferred.reject(ex);
}
return deferred.promise;
}
$stateProvider
.state('action', {
name: 'action',
url: "/actionitems",
resolve: {
loadDependencies: ['$ocLazyLoad', '$q', '$stateParams', load]
},
templateUrl: '/app/tool/action/ActionItems.html'
});
你需要创建一个constant
provider。你可以这样做:
angular.module('my-module').constant('myConstant', 'my-value');
然后在你的州提供者:
$stateProvider
.state('action', {
name: 'action',
url: "/actionitems",
resolve: {
loadDependencies: ['$ocLazyLoad', '$q', '$stateParams', 'myConstant', load]
},
templateUrl: '/app/tool/action/ActionItems.html'
});
function load ($ocLazyLoad, $q, $stateParams, myConstant, module){
// myConstant has the value 'my-value'
...
}