小编典典

AngularJS检查表单在控制器中是否有效

angularjs

我需要检查表单在控制器中是否有效。

视图:

<form novalidate=""
      name="createBusinessForm"
      ng-submit="setBusinessInformation()"
      class="css-form">
 <!-- fields -->
</form>

在我的控制器中:

.controller(
    'BusinessCtrl',
    function ($scope, $http, $location, Business, BusinessService, 
              UserService, Photo)
    {

        if ($scope.createBusinessForm.$valid) {
            $scope.informationStatus = true;
        }

        ...

我收到此错误:

TypeError: Cannot read property '$valid' of undefined

阅读 225

收藏
2020-07-04

共1个答案

小编典典

我已将控制器更新为:

.controller('BusinessCtrl',
    function ($scope, $http, $location, Business, BusinessService, UserService, Photo) {
        $scope.$watch('createBusinessForm.$valid', function(newVal) {
            //$scope.valid = newVal;
            $scope.informationStatus = true;
        });
        ...
2020-07-04