2017-03-17 45 views
0

嗨,我動態添加基於引導類型選擇的數據類型的元素。因爲總是刪除html元素並添加新的問題。表單錯誤集合仍然保持以前的錯誤,並顯示單個html元素的多個錯誤。請幫助這裏有什麼不對。動態渲染元素角形

var addDynamicControl = function (fieldInformation) { 

        if (angular.element("#" + scope.advanceSearchItem.searchItemIndex).length) { 
         angular.element("#" + scope.advanceSearchItem.searchItemIndex).remove(); 
         if (ctrl.advanceSearchForm[fieldInformation.SearchCriteriaName]) 
          ctrl.advanceSearchForm[fieldInformation.SearchCriteriaName].$setValidity("required", false); 
        } 
        var angularForm = angular.element("#" + scope.formName); 
        var result = angularForm.append(getTemplateByType(fieldInformation)); 
        $compile(result)(scope); 
       }; 

enter image description here

回答

0

插入表單元素之前,您應該清除鍵盤緩衝。下面試試

var addDynamicControl = function(fieldInformation) { 

    if (angular.element("#" + scope.advanceSearchItem.searchItemIndex).length) { 
     angular.element("#" + scope.advanceSearchItem.searchItemIndex).remove(); 
     if (ctrl.advanceSearchForm[fieldInformation.SearchCriteriaName]) 
      ctrl.advanceSearchForm[fieldInformation.SearchCriteriaName].$setValidity("required", false); 
    } 
    $timeout(function() { 
     angular.element('.typeahead') 
      .typeahead('val', ''); 
    }, 0); 

    var angularForm = angular.element("#" + scope.formName); 

    var result = angularForm.append(getTemplateByType(fieldInformation)); 
    $compile(result)(scope); 
};