bootstrap类.has-error未正确应用

时间:2016-07-04 11:19:23

标签: angularjs twitter-bootstrap

我有一个简单的反馈表单,并从angularJs进行表单验证 但是我在名字字段和评论字段上使用bootstrap has-error类 但它仅适用于名称字段 我多次查看我的代码,并没有发现这些字段代码之间的任何区别 因为该文件是项目的一部分,并且需要一些依赖关系,所以提供了一段代码和结果图片希望能够获得帮助。 谢谢你提前

这是另一个问题..我不能在我的电脑上上传照片作为文件。我试图点击这里的图像工具,但似乎要求图像的网址,我只在本地使用它们

有什么帮助吗?

但是现在这是代码: 名称字段:

<div class="form-group" ng-class="{'has-error': commentsForm.name.$error.required && !commentsForm.name.$pristine}">
                            <label class="col-sm-2 form-control-label" for="name">Your Name</label>
                            <div class="col-sm-8">
                                <input class="form-control" id="name" name="name" placeholder="Your name" ng-model="comments.name" required/>
                                <span class=" help-block" ng-show="commentsForm.name.$error.required && !commentsForm.name.$pristine">Your name?</span>
                            </div>
                        </div>

评论栏:

<div class="form-group" ng-class="{'has-error': commentsForm.commetns.$error.required && !commentsForm.comments.$pristine}">
                            <label class="col-sm-2 form-control-label" for="name">Comments</label>
                            <div class="col-sm-8">
                                <textarea class="form-control has-feedback" ng-class="{'has-error': commentsForm.comments.$error.required && !commentsForm.comments.$pristine}"
                                id="comments" name="comments" rows="5" placeholder="Your comments" ng-model="comments.comments" required></textarea>
                                <span class=" help-block" ng-show="commentsForm.comments.$error.required && !commentsForm.comments.$pristine">Your comments?</span>
                            </div>
                        </div>

提前谢谢你。

1 个答案:

答案 0 :(得分:2)

你有一个错字。它应该是

ng-class="{'has-error': commentsForm.comments.$error.required && !commentsForm.comments.$pristine}"

而不是

ng-class="{'has-error': commentsForm.commetns.$error.required && !commentsForm.comments.$pristine}"