我有一个试图从Angular指令访问的kendo-window;具体地说,我希望能够将一条消息传递给该窗口并使用它(作为弹出窗口),但我无法获得它的句柄。我尝试将它作为参数传递给指令,与传递$filter/$timeout的方式相同(见下文),并尝试使用如下代码直接访问它:
var alertMessageWindow = element.find("#customWindow");或
var alertMessageWindow = jQuery(element).find('#customWindow');我绝对不熟悉Angular指令;到目前为止,我正在使用的指令工作得很好;我只是不能访问kendo-window。
这是我正在使用的代码的基础:
<div kendo-window="customWindow"
k-options="customWindowOptions">
</div>
appModule.directive("myDirective",['$filter','$timeout',
function($filter, $timeout){
return {
restrict:'A',
scope:{
number:'=',
max:'=?',
min:'=?'
},
link: function(scope, element, attr) {
//access kendo-window here
}
};
}]);发布于 2016-06-28 00:35:21
在继续研究并在这里找到一篇很棒的文章后,http://www.undefinednull.com/2014/02/11/mastering-the-scope-of-a-directive-in-angularjs/
我找到了解决方案;通过将作用域更改为false,指令(基于我的阅读)不会被重置,因此引用kendo-window时使用,
scope.customWindow现在可以工作了。
appModule.directive("myDirective",['$filter','$timeout',
function($filter, $timeout){
return {
restrict:'A',
scope:false,
link: function(scope, element, attr) {
//access kendo-window here using scope.customWindow
}
};
}]);https://stackoverflow.com/questions/38056724
复制相似问题