javascript - Ng-Model 覆盖我在 AngularJS 输入字段中输入的任何值

标签 javascript angularjs

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/

相关文章:

javascript - 从回调函数更改模型值

angularjs - 未知的提供者 : ngGridProvider <- ngGrid

javascript - 如何在 Angular.js 中配置不同的环境?

javascript - 在 HTML5 输入字段的文本前面添加键入的数字的最佳方法?

javascript - 计算字符串中重复的字母

javascript - 在vuejs中设置激活以逐步添加?

javascript - 使用 AngularJS 1.4 像 Replaceable Tiles 一样开发 Windows?

javascript - Ctrl + C 复制网页文本 - 将额外数据复制到剪贴板

javascript - 使用 json 编码对 MySQL 数组进行分块

javascript - 如何使用 Angular js 将对象添加到存储在本地存储中的数组中?