简体   繁体   English

angularJS - ng-show - 错误

[英]angularJS - ng-show - error

that's what I have. 这就是我所拥有的。

  <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>

I think, there is a problem with the NAME attribute. 我认为,NAME属性存在问题。 If i use orderid in both, the input-tag and the following error condition it works. 如果我在两者中使用orderid,则输入标记和以下错误条件都可以使用。 But we work with Struts and i need the NAME attribute like xxxx.yyyy 但我们使用Struts,我需要像xxxx.yyyy这样的NAME属性

Is there a way to use this syntax in der ng-show exprssion? 有没有办法在der ng-show exprssion中使用这种语法?

Thanks for comments. 感谢您的评论。

I looked inside the 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;
  }
};

In your case, the input's control.$name === "order.id" , so this what happens: 在你的情况下,输入的control.$name === "order.id" ,所以这发生了什么:

  form["order.id"] = control;

The solution is to refer the control like so: 解决方案是像这样引用控件:

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

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

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