Angular的ng-bind在我的<input type="text">中不起作用
Angular ng-bind doesn't work in my <input type="text">
在我的angular应用程序中,我使用ng-bind
在modal
上显示一些静态信息。这是HTML:
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="orgTelephone" lang-tag="ActivityReport.NewContact_Modal_Telephone" class="sr-only">Telephone</label>
<input type="text" class="form-control" id="orgTelephone" ng-bind="contact.telephone" placeholder="Placeholder / Hint Texts">
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="orgEmail" lang-tag="ActivityReport.NewContact_Modal_Email" class="sr-only">Email</label>
<input type="text" class="form-control" id="orgEmail" ng-bind="contact.email" placeholder="Placeholder / Hint Texts">
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<label for="orgSuggestedFollowup" lang-tag="ActivityReport.NewContact_Modal_Followup" class="sr-only">Follow up</label>
<textarea class="form-control" rows="5" id="orgSuggestedFollowup" ng-bind="contact.followup" placeholder=""></textarea>
</div>
</div>
问题是,ng-bind
确实在我的textarea
中正确工作,在最后一行,但它在我以前的input
元素中没有输出任何东西。
我不想使用ng-model
,因为我不想在这个模式中进行双向数据绑定。我需要能够恢复任何更改,如果用户按下取消,我不能如果我使用ng-model
。
是否有办法使单向数据绑定工作与inputs
?
ng-bind用于HTML标记的内容,而不是属性。使用双花括号代替,像这样:
<input type="text" class="form-control" id="orgTelephone" value="{{contact.telephone}}" placeholder="Placeholder / Hint Texts">
解决还原的方法是不更新活动模型,而是复制要编辑的对象。
当用户准备保存时,只需用副本扩展原始文件。
$scope.item={foo:'bar'};
// make standalone copy that is not a reference to original
$scope.editItem = angular.copy($scope.item);
$scope.save = function(){
// update server and then update local data using extend
angular.extend($scope.item, $scope.editItem);
}
然后使用ng-model
指向edititem
,原始的将保持不变,直到您保存更改
<input ng-model="editItem.foo">
相关文章:
- 如何将输入(type=text)从html表单传递到javascript函数
- 铬:“;未捕获的语法错误:意外的标记:"
- 可以设置“;文件名"发生错误时显示的内联脚本标记的
- JS表单提交"无法使用Chrome数据保护程序加载此页面.尝试重新加载页面.调试信息:POST CISmtuK
- 检测电话窃听,即:<a href="电话:xxx">在UIWebview上
- 使用“+="操作人员
- //而不是在src=“”上使用http://"属性
- "未捕获的语法错误:意外的标记}"
- 可以<脚本类型=“;text/javascript”>window.location=“/"</
- "实例范围”;TypeScript类的getter/setter
- Javascript复选框函数:;缺少:在属性id之后"
- "“;变量未引用正确的对象
- "日期“;AJAX请求返回的类型值未定义
- 在文本区域中使用jQuery.text()保持换行符
- 得到"TypeError:无法读取属性'filename'未定义的“;调用“npm start
- Soundcloud api"未捕获的类型错误:无法读取属性'uri'“未定义”;
- 图像可以从源<img src=""/>.TEXT可以在没有javascript的情况下从外部
- Linkify/Clickable Text URL,但忽略那些已经包装在“;a href"'s
- Safari-->"应用程序缓存清单的MIME类型不正确:text/plain&”;
- "text长度"Internet Explorer中svg文本元素悬停时的更改