表单验证角度/引导程序

时间:2014-09-27 01:26:12

标签: angularjs angularjs-directive angularjs-scope angularjs-validation

这是FIDDLE

无法理解为什么所需的验证无效?

HTML

<div ng-app="app">
    <div ng-controller="myctrl">
        <form name="myform" class="form form-horizontal" novalidate>
            <fieldset class="fieldset" ng-show="payment == 'bankAccount'" class="form-group clearfix">
                <ul class="form-group">
                    <li ng-class="{
                'has-error':  myform.routingNumber.$invalid,
                'has-success':myform.routingNumber.$valid}">
                        <label for="routingNumber">Bank Routing Number</label>
                        <div class="" ng-show="myform.routingNumber.$error.required"> <span class="help-block">Please enter routing number</span>

                        </div>
                        <input type="text" name="routingNumber" class="form-control" required/>
                    </li>
                </ul>
            </fieldset>
        </form>
    </div>
</div>

JS

var app = angular.module('app', [])

1 个答案:

答案 0 :(得分:3)

您需要为表单上的角度验证提供ng-model才能启动。

尝试: -

<input type="text" ng-model="routingNumber" name="routingNumber" class="form-control" required/>

旁注: - 如果不在目标输入上使用id,则无法使用label for

<强> Demo