AngularJS:再次将模型设置为 = {} 不会清除 input type='url' [英] AngularJS: Set the model to be = {} again doesn't clear out input type='url'

查看:15
本文介绍了AngularJS:再次将模型设置为 = {} 不会清除 input type='url'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 fiddler 设置,当我点击重置按钮时,它应该清除输入控件,这似乎有效,但在输入 type='url'

I have a fiddler setup, when i click a reset button it should clear out the input controls, this seems to work but not when the input type='url'

这里是小提琴手

是否有问题或我不明白的地方.

Is there an issue or something that I am not understanding.

当我设置

$scope.myform = {};

这似乎清除了其他输入类型,但没有清除输入 type='url'.

This seems to clear out the other input type but the input type='url' isn't being cleared.

有人知道为什么吗?

推荐答案

当 input[type="url"] 中没有有效值时,会出现您看到的问题.无效值仅保留在视图中(输入字段)并且不会被推送到 ng-model 中的作用域变量.仅当值正确时才会更新变量.

The issue you see happens when you don't have a valid value inside the input[type="url"]. An invalid value just stays in the view (the input field) and doesn't get pushed to the scope variable inside ng-model. The variable will be updated only when and if the value is correct.

您可以通过输入有效值进行测试.重置按钮将起作用.如果您输入无效值,则不会.

You can test it by entering a valid value. The reset button will work. If you enter an invalid value it won't.

您可以通过设置 $scope.myform = null 而不是 $scope.myform = {} 来修复它.这将清空该字段,因为范围变量 (expression) 将是 undefined.一旦您在任何字段中输入有效值,它就会由 Angular 自动创建.

You can fix it by setting $scope.myform = null instead of $scope.myform = {}. This will empty the field because the scope variable (expression) will be undefined. It will be automatically created by Angular once you enter a valid value inside any of the fields.

这篇关于AngularJS:再次将模型设置为 = {} 不会清除 input type='url'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆