简体   繁体   English

为什么在禁用输入字段时评估ng-pattern

[英]Why ng-pattern is evaluated when the input field is disabled

Why does angular evaluate a pattern when the input field is disabled. 为什么在禁用输入字段时angular会评估模式。 It should behave the same way as it does when the input field is hidden? 它的行为应与隐藏输入字段时的行为相同?

Check this fiddle, Fiddle for reference 检查这个小提琴, 小提琴供参考

<div ng-app>
    <div ng-controller="PatternTestCtrl">
        <form name="ngform">
            <label for="phone">Change the text to match the placeholder:</label><br/>
            <div>
                <input type="checkbox" ng-model="checkValue" />
            </div>
             used ng-pattern <input type="text" name="phone" ng-model="phone" ng-pattern="/^\d*$/" ng-disabled="!checkValue" maxlength="12" placeholder="555-555-5555"/>
            <div>Pattern validity : {{ngform.phone.$valid}}</div>
            <br>
            <div>
                used ng-if : <input type="text" name="dummyNum" ng-pattern="/^\d*$/" ng-model="dummyNum" ng-if="checkValue" />
            </div>    
        <div> ng-if input box validity : {{ngform.dummyNum.$valid}}</div>
        </form>
    </div>
</div>

Attached images for reference 所附图片供参考
输入字段处于活动状态

禁用时

ng-if removes the element from the dom, hence the ng-pattern does not get evaluated. ng-if会从dom中移除元素,因此不会评估ng-pattern

ng-show/ng-hide , just make the element invisible, hence ng-pattern would still get evaluated. ng-show/ng-hide ,仅使元素不可见,因此ng-pattern仍将得到评估。

ng-disable and ng-pattern are different directives, why should their functionality be intermixed. ng-disableng-pattern是不同的指令,为什么要混用它们的功能。

We do in our app actually fire evaluations even on disabled fields. 我们在应用程序中执行的操作实际上会触发评估,即使是在禁用字段上也是如此。 So I really do not see the reason why the two should be intermixed. 因此,我真的不明白为什么将两者混在一起的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM