角度JS中不显示验证错误消息

时间:2016-06-23 07:47:10

标签: javascript angularjs

我是棱角分明的新人。当我尝试验证表格时,ng-hide没有从ng-show中删除。有人可以帮我解决这个问题吗?

提前致谢。 `

<div class="panel panel-default">
    <div class="panel-body">
        <h3>Add Language</h3>
        <form name="LanguageAddForm" ng-controller="LanguageAddController" class="form-horizontal" method="post"  ng-submit="submitLanguageAddForm()" novalidate  >
            <div class="panel-body">
                <div class="form-group" ng-class="{ 'has-error' : LanguageAddForm.name.$invalid && !LanguageAddForm.name.$pristine }">
                    <label class="col-md-3 control-label">Language Name:</label>  
                    <div class="col-md-9">
                        <input type="text" class="form-control" name="language.name" id="lang-name" ng-model="language.name" required />
                        <p ng-show="LanguageAddForm.name.$invalid">Please enter a valid Topic</p>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-3 control-label">Status:</label>                                        
                    <div class="col-md-9">
                        <div class="radio" ng-init="language.status=1">
                            <label>
                            <input type="radio" name="status" id="status" ng-model="language.status" ng-value="1"   >Active</label>
                            <label>
                            <input type="radio" name="status" id="status" ng-model="language.status" ng-value="0"  >
                            Not Active
                            </label>
                        </div>
                    </div>
                </div>
                <div class="btn-group pull-right">
                    <button class="btn btn-primary" type="button"  onclick="history.back(-1)" >Cancel</button>
                    <button class="btn btn-primary" type="submit" ng-disabled="LanguageAddForm.$invalid" >Submit</button>
                </div>
            </div>
        </form>
    </div>
</div>

`

1 个答案:

答案 0 :(得分:0)

您可以这样使用验证邮件。

<input type="text" class="form-control" name="language.name" id="lang-name" ng-model="language.name" ng-pattern=""  required/>
    <span ng-show="form_name.language.name.$error.pattern">please enter valid value</span>

了解更多信息,请阅读此Angular validation doc