无法从dom手动删除角度材料md-autocomplete元素

时间:2016-02-16 20:02:08

标签: javascript angularjs autocomplete material

尝试通过esc或blur删除自动完成元素,并以这种方式销毁其范围(在外部点击时调用stopEdit或esc键码事件):

 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

在这种情况下是否有正确销毁范围的方法,或等待指令完成其内部转义事件处理?

0 个答案:

没有答案