Angular ng-model 正在覆盖我放入输入或文本区域值字段中的任何值或表达式。如果我删除 ng-model,一切都会正常工作,但是一旦我添加 ng-model,它就会使该字段为空..我尝试使用 Controller 中的一些值填充 ng-model,但它不起作用..
<input type="text" ng-model="note.title" value="{{title}}">
<textarea ng-model="note.notes">{{notes}}</textarea>
虽然表达式值在元素检查器中正确呈现并且存在,但如果模型存在,则 View 显示空白表单,否则它显示正确的值。
最佳答案
HTML 复制代码
<form action="update.php" ng-controller="EditController" method="post" id="UpdateForm">
<input type="text" value="{{title}}">
<textarea>{{notes}}</textarea>
<input type="submit" value="Submit">
</form>
Javascript代码
var notesId = $routeParams.notesId;
$scope.editNotes = function() {
$http.post('www/edit.php', notesId)
.success(function(data) {
$scope.allNotes = data;
//here i updated value
$scope.notes = $scope.allNotes[0].text_notes;
$scope.title = $scope.allNotes[0].notes_title;
});
};
$scope.editNotes();
$scope.notes
和 $scope.title
的值是我想要在表单字段值中显示的值,因为我正在更新一些内容并且我不希望我的用户从头开始。
关于javascript - Ng-Model 覆盖我在 AngularJS 输入字段中输入的任何值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28471269/