Angular-laravel形式错误消息

时间:2017-11-06 16:09:15

标签: php angularjs laravel validation webforms

我在表单验证为false时尝试显示错误消息。但是消息总是可见的。

<body ng-app="myApp2" >
    @include('header')
    <div ng-controller="ExampleController">
        <form name="user-form" method="POST" action="{{route('registrationUser')}}">
            {{route('registrationUser')}}">
            <div class="form-group">
                <div class="form-group">
                    <label for="firstName"  class="col-sm-3 control-label">
                        Номер телефона
                    </label>
                    <input type="text" ng-pattern="phoneNumbr" name="phone" required>
                    <span class="error" ng-show="myForm.phone.$error.required">
                        Required!
                    </span>
                    <span class="error" ng-show="myForm.phone.$error.minlength">
                        Phone no not less that 10 char.
                    </span>
                    <span class="error" ng-show="myForm.phone.$error.maxlength">
                        Phone no not more than 11 char.
                    </span>
                    <br><span class="error" ng-show="myForm.phone.$error.pattern">
                        Please match pattern [+91-036-78658 || 91-036-78658]
                    </span>
                </div>
                <div class="form-group">
                    <button ng-click='SaveUser()' name="Регистрация" class="btn btn-primary col-sm-offset-3">
                        Регисрация
                    </button>
                    {{ csrf_field() }}
                </div>
            </div>
        </form>
    </div>
    <script>
        var app = angular.module('myApp2', []);
        $scope.positions = '';
        app.controller('ExampleController', function($scope) {
            $scope.positions=Positions;
            $scope.phoneNumbr = /^\+?\d{2}[- ]?\d{3}[- ]?\d{5}$/;
        });
    </script>
</body>

1 个答案:

答案 0 :(得分:0)

尝试将您的javascript包装在IIFE中,如下所示:

(function() { code })()

顺便说一下,您应该考虑将标准{{}}的角度插补大括号更改为其他内容。它可能有问题,因为刀片使用相同的语法。