value 和 ng-model 有冲突

value and ng-model are conflicted

我正在开发一个 angular 表单,用户可以发送他们的数据更新并在需要时取消编辑。

我发现我应该将编辑保存在一个单独的变量中。所以这是一些代码:

//if editor is turned off it shows the saved value
<div data-ng-hide="editorEnabled" class="margin-bottom-top">{{document.title}}</div>

//if the editor is turned on it should save the edits in another variable to keep the older one
<input data-ng-show="editorEnabled" class="margin-bottom-top" data-ng-model="document.edit.title" value="{{document.title}}" type="text">

所以现在我可以访问两者 - 以前的标题和新编辑的标题。但我希望以前的标题在 input-field 中显示为值,这样用户就可以看到当前值是什么,而不必再次输入。使用占位符它可以工作,但这不是我想要的。当我检查我可以看到的元素时,正确的值是绑定的,但它没有显示出来。

我知道 ng-model 和 value 相互冲突,因此它不起作用。我也试过 ng-value 但它也不起作用。这种情况有什么解决办法吗?

尝试设置

$scope.document.edit.title = $scope.document.title

并从输入

中删除value=""

不要同时使用两者,将值设置为 ng-model

$scope.document.edit.title

它会自动为该输入设置值。