AngularJS:设置模式为= {}再次不清除输入类型='URL' [英] AngularJS: Set the model to be = {} again doesn't clear out input type='url'
问题描述
我有一个小提琴手设置,当我点击一个复位按钮,它应该清除掉输入控件,这似乎工作,但不是当输入键入='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 = {};
这似乎清除出其他输入类型,但输入类型='URL'没有被清除。
This seems to clear out the other input type but the input type='url' isn't being cleared.
任何人都知道为什么吗?
Anyone know why?
推荐答案
当你没有输入[类型=URL]里面的一个有效的值,你看到的问题发生。无效值只是停留在视图中(输入字段的),并没有得到被推到NG-模型内部范围的变量。变量将只更新时,如果该值是正确的。
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 = {}
。这将清空字段,因为范围变量(前pression 的)会的未定义的。它将被角,一旦你里面的任何字段输入有效的值自动创建。
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:设置模式为= {}再次不清除输入类型='URL'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!