当尝试通过 esc 或 blur 删除自动完成元素并以这种方式破坏其范围时(在外部单击或 esc 键码事件时调用 stopEdit):
function stopEdit() {
autoCompleteController.clear();
autoCompleteController.blur();
$timeout(function () {
if (angular.isDefined($attrs.ngBind)) {
$element.empty();
$element.text($scope.$eval($attrs.ngBind));
}
input = undefined;
autoCompleteController = undefined;
if (inputScope) {
inputScope.$destroy();
inputScope = undefined;
}
$element.removeClass('autocomplete-input-active');
angular.element('body').off('click', clickOutsideHandler);
angular.element('.md-scroll-mask').css({
position: 'initial'
});
}, 100); //here I've added timeout, which make code work, but it's not really good solution
}
错误下降:
TypeError: Cannot read property '$setViewValue' of undefined
at angular-material.js:18874
at processQueue (angular.js:14745)
at angular.js:14761
at Scope.parent.$get.Scope.$eval (angular.js:15989)
at Scope.parent.$get.Scope.$digest (angular.js:15800)
at angular.js:16028
at completeOutstandingRequest (angular.js:5507)
at angular.js:5784
在这种情况下有没有办法正确地破坏作用域,或者等待指令完成其内部转义事件处理?