为什么ng-bind-html进入无限循环

Why ng-bind-html goes into infinite loop ?

本文关键字:无限循环 ng-bind-html 为什么      更新时间:2023-09-26

HTML:

<div tooltip="page 1 of 6, 2 of 11, 6 of 19" tooltip-placement="right"  ng-bind-html="getField('page_01','Subject','txt_sub_propAdd')"></div>

角:

$scope.currentField='';//Use to hendle Angular Deigest Loop
    $scope.getField = function(page, section, field) {
        console.log(i++,section,field);
        $scope.currentField=$sce.trustAsHtml(self.data.HTMLData[page][section][field]);
        return $scope.currentField;
};

控制台输出:

    0 "Subject" "txt_sub_propAdd"
    1 "Subject" "txt_sub_propAdd"
    2 "Subject" "txt_sub_propAdd"
    3 "Subject" "txt_sub_city"
    4 "Subject" "txt_sub_city"
    5 "Subject" "txt_sub_city"
    6 "Subject" "txt_sub_state"
    7 "Subject" "txt_sub_state"
-----
-----
-----
-----
till infinity

屏幕上的输出:

<div tooltip="page 1 of 6, 2 of 11, 6 of 19" tooltip-placement="right" ng-bind-html="getField('page_01','Subject','txt_sub_propAdd')" class="ng-binding"><input type="text" label="Property Address" name="txt_sub_propAdd" value=" " maxlength="60" minlength="30" required="" id=" " class="form-control" regex="[^A-Za-z0-9_-/]" ng-model="subject.txt_sub_propAdd"></div>

PS:我必须在屏幕上显示600多个字段(文本框,单选按钮,复选框(。还要告诉我如何在控制器中获得 ng 模型值。

好的,我将结果保存在数组中而不是调用函数中。此外,我还使用此指令使我的字段可用于角度。

.directive('compile',function($compile, $timeout){
    return{
        restrict:'A',
        link: function(scope,elem,attrs){
            $timeout(function(){                
                $compile(elem.contents())(scope);    
            });
        }        
    };
});