我正在使用 ui-router 并且我正在解析一些数据我想将解析注入(inject)我的自定义指令,下面是我正在做的代码
module portal {
$stateProvider.state('portal', {
url: '/demo',
template: tpl.html,
abstract: true,
resolve: {
demoResolve:function(){
return 'foo';//here i am returing a promise
}
});
}
module portal.directives{
export class demoDirevtive{
static $inject =['demoResolve'];
constructor(demoResolve){
console.log(demoResolve)
var directive: ng.IDirective = {};
directive.link = (scope, element, attrs, ctrl) => {
};
directive.restrict = "EAC";
return directive;
}
}
}
但我收到未知提供者的错误
最佳答案
从阅读他们的代码来看,这似乎是不可能的,他们有一个局部变量,他们将其注入(inject)到您在 View 上定义的 Controller 中,它也无法通过 $inject 服务访问。
最简单的解决方案是将它放在 Controller 的范围内,然后在指令中使用它。
您还可以创建一个真正的服务,它将在您的应用程序中保存所有已解析的对象,即:
resolve: {
demoResolve: ['myResolvingService', function(resolver) {
resolver.myValue = 'Foo';
return 'Foo';
}]
我知道这不是您要找的东西,但它看起来不像是受支持的。
关于angularjs - 注入(inject) ui-router resolve 指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26354021/