gpt4 book ai didi

javascript - AngularJS-ng-show-错误

转载 作者:行者123 更新时间:2023-12-02 17:45:12 25 4
gpt4 key购买 nike

这就是我所拥有的。

  <form action="/asvabo/ChangeCustomerRegister.do" method="post"  
name="CustomerRegisterForm">
...
<input ... type="text" ... name="order.id" pattern="[0-9]*" required
ng-model="orderid" ng-trim="true"/>

<!-- Label for show that the input is required -->
<span class="error"
ng-show="CustomerRegisterForm.order.id.$error.required">Required!
</span>
....
</form>

我认为 NAME 属性有问题。如果我在输入标签和以下错误条件中都使用 orderid ,则它可以工作。但我们使用 Struts,我需要像 xxxx.yyyy

这样的 NAME 属性

有没有办法在 der ng-show 表达式中使用此语法?

感谢您的评论。

最佳答案

我查看了 form controller source code 的内部:

form.$addControl = function(control) {
// Breaking change - before, inputs whose name was "hasOwnProperty" were quietly ignored
// and not added to the scope. Now we throw an error.
assertNotHasOwnProperty(control.$name, 'input');
controls.push(control);

if (control.$name) {
form[control.$name] = control;
}
};

在您的情况下,输入的 control.$name === "order.id",所以会发生什么:

  form["order.id"] = control;

解决方案是像这样引用控件:

<span class="error" 
ng-show="CustomerRegisterForm['order.id'].$error.required">Required!
</span>

关于javascript - AngularJS-ng-show-错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21829979/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com