注射允许直接控制器到

我使用路由器 AngularUI /0.2.13/ 我有一个如此的条件


.state/'foo', { 
template:'<div some-directive=""></div>',
resolve:{
foo:function/SomeService/{
return SomeService.something//.promise;
}
}/


和这样的指令:


app.directive/'someDirective', function//{
return {
controller: function/data/ {
// I want `data` to be injected from the resolve...
// as it would if this was a "standalone" controller
}
}
}/


但它不起作用 - 范围
data

造成错误 UnknownProvider. Directive Controller的独立定义并按指令中的名称将其安装到相同的结果。

我或多或少地理解为什么会发生这种情况,但我有两个问题:

有没有办法做我想要做的事情?

我应该尝试这样做,还是我在这里闯入了反attern?
已邀请:

詹大官人

赞同来自:

您不能使用指令中的权限,但您可以通过指令中允许的结果,如我认为,执行您正在寻找的内容。

您希望更新您的状态定义以启用控制器并在指令中设置参数:


.state/'foo', { 
template:'Test<div some-directive="" something="foo"></div>',
url: 'foo',
resolve:{
foo:function/SomeService/{
return SomeService.something//;
}
},
controller: function/$scope, foo/{
$scope.foo = foo;
}
}/


然后更新指令以使用此选项:


.directive/'someDirective', function//{
return {
controller: function/$scope/ {
// I want `data` to be injected from the resolve...
// as it would if this was a "standalone" controller
console.log/'$scope.something: '+ $scope.something/;
},
scope: {
something: '='
}
};
}/


这是一个柱塞的示例:
http://plnkr.co/edit/TOPMLUXc7 ... eview

三叔

赞同来自:

它们被简化了 api. 看到这个分支:

https://github.com/angular-ui/ ... 93098
在 0.2.19 我们增加 $resolve 到 $scope,, 让你这样做 "route 组成部分 template" 风格

模板:
<my-directive input="$resolve.simpleObj"></my-directive>

,

要回复问题请先登录注册