【发布时间】:2015-08-31 02:12:12
【问题描述】:
我正在研究一种角度形式,用户可以发送数据更新并在需要时取消编辑。
我发现我应该将编辑保存在一个单独的变量中。所以这里有一些代码:
//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">
所以现在我可以访问两者 - 以前的标题和新编辑的标题。但我希望前一个标题在输入字段中显示为值,这样用户就可以看到当前值是什么,而不必再次输入。使用占位符它可以工作,但这不是我想要的。当我检查我可以看到的元素时,正确的值是绑定但它没有显示出来。
我知道 ng-model 和 value 相互冲突,因此它不起作用。我也尝试了 ng-value ,但它也不起作用。这种情况有解决办法吗?
【问题讨论】:
-
你能提供一个 plunker、jsfiddle 或类似的东西吗?
标签: javascript html angularjs data-binding