0

在 AngularJS 的引导程序之后,如何使用 ngModel 将输入控件与 JavaScript 绑定?

我尝试ng-model通过方法添加属性setAttribute,但没有奏效!

    function FormController($scope) {
        $scope.name="OK";

        $scope.createBind=function(){
                    var texteditor=document.getElementById("test");
                    if(texteditor.getAttribute("ng-model")==null){
                        texteditor.setAttribute("ng-model","name");
                        $scope.$apply();
                    }
                }
    }

<input type="text" id="test">
<button ng-click="createBind()">Bind</button>
4

1 回答 1

0

Angular don't get changes if you make them via javascript or jquery or etc...

You should call $scope.$apply() to get such changes manually...

Here is a good article for you to understand $scope.apply()...

于 2014-03-18T05:50:30.970 回答