Javascript 在DOM被angular更新后调用函数
我有一个切换显示搜索面板的变量的函数,当面板可见时,我需要调用resize函数来刷新ACE编辑器(面板使编辑器变小) 在html中,我有:Javascript 在DOM被angular更新后调用函数,javascript,angularjs,ace-editor,Javascript,Angularjs,Ace Editor,我有一个切换显示搜索面板的变量的函数,当面板可见时,我需要调用resize函数来刷新ACE编辑器(面板使编辑器变小) 在html中,我有: <div class="search-panel" ng-show="searchReplace"> <button type="button" ng-click="search(false)" class="close" data-dismiss="modal" aria-hidden="true">×&
<div class="search-panel" ng-show="searchReplace">
<button type="button" ng-click="search(false)" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<form name="searchForm">
...
我在keydown事件中调用该函数:
$(document.documentElement || window).keydown(function(e) {
if (e.ctrlKey) {
if (e.which == 82) { // CTRL+R
$scope.$apply(function() {
$scope.search(true, true);
});
} else if (e.which == 81) { // CTRL+Q to test resize - it's working
editor.resize();
} else if (e.which == 70) { // CTRL+F
$scope.$apply(function() {
$scope.search(true);
});
e.preventDefault();
}
}
});
我最后使用了jQuery show/hide and call resize after。在Angular中不应该使用直接的keydown事件,而应该使用ng keydown。@ZekeSonxx如何将keydown添加到整个文档?@ZekeSonxx我已将ng keydown添加到正文中,并且在更改DOM后不会调用resize。
$(document.documentElement || window).keydown(function(e) {
if (e.ctrlKey) {
if (e.which == 82) { // CTRL+R
$scope.$apply(function() {
$scope.search(true, true);
});
} else if (e.which == 81) { // CTRL+Q to test resize - it's working
editor.resize();
} else if (e.which == 70) { // CTRL+F
$scope.$apply(function() {
$scope.search(true);
});
e.preventDefault();
}
}
});