角度UI模式和ng消息不起作用

时间:2016-01-24 11:59:39

标签: angularjs

In this plunk我在Angular ui Modal上使用ng-messages验证了字段。表单上的字段是必需的,但如果我开始键入值,则会错误地显示所需的错误消息。那是为什么?

HTML

<div ng-app="app" ng-controller="myCtl">

   <script type="text/ng-template" id="myModalContent.html">

        <form name="form1" ng-submit="submitForm(form1)" novalidate>

            <div class="modal-header">
                <h4 class="modal-title">The Title</h4>
            </div>
                Enter userid  

                 <input type="text" name="userid" ng-model="userid" required />
                 <div ng-show="form1.$dirty" ng-messages="form1.userid.$error" style="color:red">
                    <div ng-message="required">You did not enter a field</div>
                 </div>

            <div class="modal-footer">
                <button type="submit">Submit</button>
            </div>

        </form>
    </script>
</div>

的Javascript

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

app.controller('myCtl', function($scope,$uibModal) {

      $scope.modalInstance = $uibModal.open({
          animation: false,
          templateUrl: 'myModalContent.html',
          scope: $scope
        });

        $scope.submitForm = function(form) {
          alert ("form valid = " + form.$valid);
        };    
});

1 个答案:

答案 0 :(得分:1)

我意识到了这个问题:我忘了宣布像这样的ngMessages

var app = angular.module('app', ['ui.bootstrap','ngMessages']);

Angular默默地忽略此错误