我有这样一个简单的html形式
<div ng-app="app">
<form action="" ng-controller="testController" id="parent">
</form>
</div>
Run Code Online (Sandbox Code Playgroud)
现在我想从javascript添加一个输入字段
var app = angular.module('app',[]);
app.controller('testController',testController);
function testController($scope){
var input = document.createElement('input');
var form = document.getElementById('parent');
input.setAttribute("type","number");
input.setAttribute("id","testId");
input.setAttribute("name", "test");
input.setAttribute("ng-model","test");
form.appendChild(input);
}
Run Code Online (Sandbox Code Playgroud)
输入字段也会按预期生成
<input type="number" id="testId" name="test" ng-model="test">
Run Code Online (Sandbox Code Playgroud)
但是此输入字段之间的ng-model $scope.test不起作用。