gpt4 book ai didi

javascript - value 和 ng-model 是冲突的

转载 作者:行者123 更新时间:2023-12-02 16:05:01 25 4
gpt4 key购买 nike

我正在开发一种 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">

现在我可以访问之前的标题和新编辑的标题。但我希望前一个标题在输入字段中显示为值,以便用户可以看到当前值是什么,而不必再次输入。使用占位符它可以工作,但这不是我想要的。当我检查该元素时,我可以看到,正确的值已绑定(bind),但它没有显示。

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

最佳答案

尝试设置

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

并从输入中删除value=""

关于javascript - value 和 ng-model 是冲突的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30847593/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com