将ng模型绑定到动态创建的控件

时间:2018-08-21 12:10:33

标签: angularjs

我正在像动态创建控件

<div class="ctrlContainer" ng-repeat="c in Data.Controls">
            <div class="divRow" ng-bind- 
html="trustHTML(getTypeBasedHTML(c.HTMLControlType,Data.RootObjectName + '.'+ 
c.ModelName,c.NeedLabel,c.LabelText))"></div>
        </div>

我的代码定义为

$scope.getTypeBasedHTML = function (type, ModelBinding, NeedLabel, 
LabelText) {
        var returnHtmltxt = ""
        if (type == "text" || type == "number" || type == "email" || type == 
"date" || type == "checkbox" || type == "radio") {
            if (NeedLabel)
                returnHtmltxt += "<div class='divCell label-column'>" + 
LabelText + "</div>"
            returnHtmltxt += "<div class='divCell'><input type='" + type + 
"' ng-model='" + ModelBinding + "' /></div>"
        }
        return returnHtmltxt
    }

上述功能正在按预期方式创建控件,并使用“ ng-model”属性将其呈现到页面中,但是当我更改控件(输入文本框)的值时,模型不会在范围内更新。 有人可以调查一下吗? 谢谢

注意:绑定到动态元素的模型也会动态创建到$ scope

0 个答案:

没有答案