[英]accessing rootScope in directive
I've tried a million ways to access a rootScope variable from within this elasticui based directive with zero luck. 我已经尝试了百万种方法,从这个基于Elasticui的指令中以零运气访问rootScope变量。 Here is the directive, bearing in mind $rootScope is indeed being passed into its parent controller. 这里是指令,请记住,$ rootScope确实已传递到其父控制器中。
var elasticui;
(function (elasticui) {
var directives;
(function (directives, rootScope) {
var IndexDirective = (function () {
function IndexDirective() {
var directive = {};
directive.restrict = 'EAC';
directive.controller = elasticui.controllers.IndexController;
directive.link = function (scope, element, attrs, indexCtrl, rootScope) {
console.log("Updated Index: " + $rootScope.esIndex);
indexCtrl.indexVM.index = scope.$eval(attrs.euiIndex);
};
return directive;
}
return IndexDirective;
})();
directives.IndexDirective = IndexDirective;
directives.directives.directive('euiIndex', IndexDirective);
})(directives = elasticui.directives || (elasticui.directives = {}));
})(elasticui || (elasticui = {}));
Elsewhere I'm setting $rootScope.esIndex to the index I'd like to point to but I'm getting "$rootScope is not defined". 在其他地方,我将$ rootScope.esIndex设置为我要指向的索引,但是却得到“ $ rootScope未定义”。 I've tried setting the directive's scope property to false, tried setting up a watcher on $rootScope.esIndex as part of the link functions return value but no matter what I do, I can't seem to figure it out. 我尝试将指令的scope属性设置为false,尝试在$ rootScope.esIndex上设置观察程序,以作为链接函数返回值的一部分,但是无论我做什么,我似乎都无法弄清楚。
I think part of the problem for me is this structure is a little cryptic from a directive standpoint for a newer angular person to digest. 我认为对我来说部分问题是,从指令的角度来看,这种结构对于一些较新的有角度的人来说,是有点晦涩难懂的。 This is a block in a far larger set of directive definitions so it's just hard for me to grasp. 这是更大范围的指令定义中的一个障碍,因此对我来说很难理解。
Any ideas how I can easy grab $rootScope in here? 有什么想法可以轻松地在这里获取$ rootScope吗?
Thanks a TON in advance! 提前感谢吨!
Seeing more of your code would help. 查看更多代码将有所帮助。 Specifically when you say "$rootScope is indeed being passed". 特别是当您说“ $ rootScope确实已通过”时。 However, with this limited info why don't you try changing this line: 但是,由于信息有限,您为什么不尝试更改此行:
(directives = elasticui.directives || (elasticui.directives = {}));
to something like 像
(directives = elasticui.directives || (elasticui.directives = {}, rootScope));
At a glance it appears your self executing function isn't being passed the rootScope parameter it expects. 乍一看,似乎您的自执行函数没有传递期望的rootScope参数。 Good luck! 祝好运!
edit: Also 编辑:也
console.log("Updated Index: " + $rootScope.esIndex);
Should probably not have the dollar sign. 应该可能没有美元符号。
edit: Comments have much more info! 编辑:评论有更多信息!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.