我试过一百万种方法来从这个基于弹性的指令中访问一个rootScope变量,但没有运气。这里是指令,铭记$ rootScope确实被传递到它的父控制器。访问指令中的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 = {}));
在其他地方我$ rootScope.esIndex设置为索引,我想指出,但我得到“$ rootScope没有定义”。我试着将指令的范围属性设置为false,尝试在$ rootScope.esIndex上设置一个观察器作为链接函数返回值的一部分,但无论我做什么,我似乎都无法弄清楚。
我认为问题的一部分是这个结构有点隐晦从一个新的角度消化的指令立场。这是一组更大的指令定义中的一个块,所以我很难掌握。
任何想法,我可以轻松抢到$ rootScope在这里?
非常感谢TON!
你应该在这里肯定会提供更多的代码,但我会在初看起来你会传递'rootScope'而不是'$ rootScope'到函数中。这可能是问题的一部分。 –