在 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>