Javascript 无法通过ng模型获取隐藏字段值
我是Angular js的新手,我正在努力通过ng-model访问隐藏字段值。基本上,我使用模式进行编辑。以下是我的控制器代码:Javascript 无法通过ng模型获取隐藏字段值,javascript,html,angularjs,Javascript,Html,Angularjs,我是Angular js的新手,我正在努力通过ng-model访问隐藏字段值。基本上,我使用模式进行编辑。以下是我的控制器代码: $scope.update = function(){ $http({ method:'POST', url:'http://localhost:8000/api/v1/edit', data: {id: $scope.editId , name:
$scope.update = function(){
$http({
method:'POST',
url:'http://localhost:8000/api/v1/edit',
data: {id: $scope.editId , name: $scope.edit_name, email: $scope.edit_email, password: $scope.edit_password}
}).then(function(response){
$scope.updated_form_data_list = response.data;
});
};
});
我正试图通过javascript为每条记录设置Id:
<tbody ng-repeat="form_data in form_data_list"> //Displaying records from DB inside the Table
<tr>
<td>@{{ form_data.name }}</td>
<td>@{{ form_data.email }}</td>
<td>@{{ form_data.password }}</td>
<td><Button type="button" onclick="setEditId(this.id)" data-toggle="modal" data-target="#modal_content" id="@{{form_data.id}}" ><span class="glyphicon glyphicon-pencil"></span></Button></td>
</tr>
</tbody>
//在表中显示数据库中的记录
@{{form_data.name}
@{{form_data.email}
@{{form_data.password}}
我已经通过javascript设置了hidden的值,如下所示:
<script type="text/javascript"> //setting the value of hidden field with id
function setEditId(id){
document.getElementById('editId').value=id;
}
</script>
//设置id为的隐藏字段的值
函数setEditId(id){
document.getElementById('editId')。value=id;
}
我在以下代码中将ng模型作为editId:
<div class="modal fade" id="modal_content" role="dialog">
...
<input type="hidden" name="id" id="editId" ng-model="editId">
...
<button ng-click="update()">Submit</button>
...
...
提交
当我点击提交按钮时,我可以发布除id之外的其他值。请为我推荐任何解决方案。提前谢谢你 由于您使用js设置editID的值,因此不更新模型,请使用
$scope.editId = id;
要更改输入的值,请使用简单的技巧…不要调用javascript来设置Id,而是使用ng单击通过控制器进行设置
$scope.storeId=function(id){
$scope.id=id;
}
并通过
<Button type="button" ng-click="storeId(form_data.id)" data-toggle="modal" data-target="#modal_content">
<span class="glyphicon glyphicon-pencil">