简体   繁体   English

验证非输入字段的角度

[英]Validation of non-input field in angular

I have following piece of code: 我有以下代码:

<div class="field">
    <div class="ui message">
        <p> {{ ctrl.someValueFetchedFromDatabase}} </p>
    </div>
</div>

Now, I would like to attach some validation to this <div> . 现在,我想对此<div>附加一些验证。 I mean some logical condition (depending on values in controller) which is checked during submiting form (I have binded function in conroller with this submit button). 我的意思是在提交表单时检查了一些逻辑条件(取决于控制器中的值)(我已使用此提交按钮将控件绑定到了控制器中)。

The result of validating should be message, almost exactly the same as here: 验证的结果应该是message,几乎与此处完全相同: 在此处输入图片说明

To sum up: I am searching for a way to validate non-input field in some specific way. 总结:我正在寻找一种以特定方式验证非输入字段的方法。

I think that what you are looking for is: 我认为您正在寻找的是:

<div class="field">
    <div ng-if="ctrl.resultOfTheValidation" class="ui message">
        <p> {{ ctrl.someValueFetchedFromDatabase}} </p>
    </div>
</div>

Where ctrl.resultOfTheValidation would have a true/false value. 其中ctrl.resultOfTheValidation的值为true / false。 I hope this helps you :) 我希望这可以帮助你 :)

set name for your form and input and set rquired attribute for your input and set novalidate attribute to your form. 为表单和输入设置名称,为输入设置rquired属性,并为表单设置novalidate属性。

<div class="field">
    <div class="ui message" ng-show="{{formName.inputName.$error.required && formName.inputName.$dirty }}">
        <p> {{ ctrl.someValueFetchedFromDatabase}} </p>
    </div>
</div>

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

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