如何在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>
答案 0 :(得分:0)
如果您通过javascript或jquery等制作它们,Angular不会得到更改...
您应该致电$scope.$apply()
手动获取此类更改...
这是一个很好的article,让您了解$scope.apply()
...