Angularjs 角度-ng消息可以有or语句吗?

Angularjs 角度-ng消息可以有or语句吗?,angularjs,Angularjs,我有两个输入字段,如果其中一个为空,我希望显示一条错误消息。我正在尝试使用|,但它不起作用-在“ng消息”中允许这样做吗 代码: 至少需要2个 以及输入本身 <input name="o1" ng-model="main.o1ToAdd" type="text" placeholder="Yes" required/> <input name="o2" ng-model="main.o2ToAdd" type="text" plac

我有两个输入字段,如果其中一个为空,我希望显示一条错误消息。我正在尝试使用
|
,但它不起作用-在“ng消息”中允许这样做吗

代码:


至少需要2个
以及输入本身

<input name="o1" ng-model="main.o1ToAdd" type="text"
          placeholder="Yes" required/>

<input name="o2" ng-model="main.o2ToAdd" type="text"
          placeholder="Yes" required/>


您不能在
ng消息中使用|
。ng消息的值应该是一个对象,每个键表示一个布尔值

{
  required: false,
  minlength: true,
  customErrorCondition: false
}
作为评估多个条件的变通方法,您可以使用

<div ng-messages="{ required: !main.o1ToAdd || !main.o2ToAdd }"
   ng-if="postForm.o1.$touched || postForm.o2.$touched">
   <!-- This message is shown when either of the inputs is missing -->
   <span ng-message="required">at least 2 are required</span>
</div>

至少需要2个

编辑:添加了您不能在
ng消息中使用|
。ng消息的值应该是一个对象,每个键表示一个布尔值

{
  required: false,
  minlength: true,
  customErrorCondition: false
}
作为评估多个条件的变通方法,您可以使用

<div ng-messages="{ required: !main.o1ToAdd || !main.o2ToAdd }"
   ng-if="postForm.o1.$touched || postForm.o2.$touched">
   <!-- This message is shown when either of the inputs is missing -->
   <span ng-message="required">at least 2 are required</span>
</div>

至少需要2个
编辑:添加了

简单解决方案:

<p ng-show="postForm.o1.$error.required || postForm.o2.$error.required">
    at least 2 are required
</p>

至少需要2个

简单解决方案:

<p ng-show="postForm.o1.$error.required || postForm.o2.$error.required">
    at least 2 are required
</p>

至少需要2个