附加控制器的角度路径问题

时间:2017-08-03 06:14:14

标签: angularjs angular-routing

我正在为我的项目使用angular route。我的项目结构如下。

  

索引页

<body ng-app="myApp">
  <div ng-view></div>


   <script src="resources/js/angular.js" type="text/javascript"></script>
   <script src="resources/angular/angular-route.js" type="text/javascript"></script>
   <script src="resources/js/route.js" type="text/javascript"></script>
   <script src="resources/js/quotation.js" type="text/javascript"></script>
   <script src="resources/js/container_details.js" type="text/javascript"></script> 
   <script src="resources/angular/angular-modal-service.js" type="text/javascript"></script>
   <script src="/containers/resources/js/user-registration.js" type="text/javascript"></script>
 </body>

我的route.js文件

var app = angular.module('myApp',['ngTable','jcs-autoValidate','ngRoute']);

    // configure our routes
    app.config(function($routeProvider,$locationProvider) {

        $routeProvider
        .when('/containers', {
            templateUrl : 'template.jsp'


        })
            .when('/container-details', {
                templateUrl : 'container-details.jsp',
                controller  : 'myCtrl'

            })
            .when('/quotation-approve', {
                templateUrl : 'quotation_approve.jsp',
                controller  : 'ourCtrl'

            })
                .when('/user-registration', {
                templateUrl : 'user-registration.jsp',
                controller  : 'userCtrl'

            })


        $locationProvider.html5Mode(true);
    });

/*  app.config(["$routeProvider", "$locationProvider", function ($routeProvider, $locationProvider) {  
        $locationProvider.html5Mode(true);*/

我将所有模块定义如下:

var app = angular.module("myApp");

当我加载页面错误发生时。错误说 enter image description here

  

用户registration.js

var app = angular.module("myApp");

app.run(function(defaultErrorMessageResolver, validator) {
  validator.setValidElementStyling(false);
  defaultErrorMessageResolver.getErrorMessages().then(function(errorMessages) {
    errorMessages['min-length'] = 'Username must be at least {0} letters';
    errorMessages['max-length'] = 'Username must be  {0} letters Only';
    errorMessages['pwError'] = "Password should be atleast 8 characters long and should contain one number,one character and one special character";
    errorMessages['passwordVerify'] = "password not matched";
    errorMessages['validEmail'] = "Please enter a valid email address";
  });

});


app.controller('userCtrl', function($scope, $http, NgTableParams, $timeout, $filter) {

  $scope.getAllUserDetails = function() {
    $http({
      method: "GET",
      url: "/containers/getUserRolle"
    }).then(function mySucces(response) {
      $scope.getAllRolesDetails();
      $scope.userRolless = response.data.userRolles;
      //        console.log( $scope.userRolless);
      $scope.getDatas();
    }, function myError(response) {
      $scope.userRolless = response.data.userRolles;
    });
  }


  $scope.getAllTableData = function() {
    // $scope.edituserdetails={};
    //$scope.edituserdetails.activeuser=true;
    $http({
      method: "GET",
      url: "/containers/getUserRolle"
    }).then(function mySucces(response) {
      //		     	$scope.getAllRolesDetails();
      $scope.userRolless = response.data.userRolles;
      //		        console.log( $scope.userRolless);
      $scope.getDatas();
    }, function myError(response) {
      $scope.userRolless = response.data.userRolles;
    });
  }

  $scope.getDatas = function() {
    console.log("tesssst" + $scope.userRolless);
    //console.log("tesssst"+$scope.userRolless.object.name);
    $scope.tableParams = new NgTableParams({
      page: 1, // show first page
      count: 5,
      // count per page
      // filter: {name: '' },
      // sorting: { username: "asc" },

    }, {
      dataset: $scope.userRolless
    });

  }






  $scope.getAllRolesDetailsById = function(roleId) {

    $http({
      method: "GET",
      url: "/containers/getUserRoleById",
      params: {
        roleId: roleId
      }
    }).then(function mySucces(response) {
      console.log(response.data.userAllRollesById);
      $scope.userAllRolles = response.data.userAllRollesById;
      $scope.edituserdetails.role = $scope.userAllRolles[0];

      // console.log("user Active status"+ $scope.edituserdetails.activeuser);
    }, function myError(response) {
      console.log(response.data.userAllRolles);
      $scope.userAllRolles = response.data.userAllRollesById;
    });

  }

  $scope.editUserFunction = function(usersid) {

    $http({
      method: "GET",
      url: "/containers/getUserDetails",
      params: {
        userId: usersid
      }
    }).then(function mySucces(response) {
      $scope.edituserdetails = response.data.userDetails;
      $scope.username = response.data.userDetails.username;
      $scope.getAllRolesDetailsById($scope.edituserdetails.roleId);
      console.log(response.data.userDetails);

      console.log("user Active status" + response.data.userDetails.userstatus);
      if (response.data.userDetails.userstatus === 'Y') {
        $scope.edituserdetails.activeuser = true;
      } else {
        $scope.edituserdetails.activeuser = false;
      }
      $scope.edituserdetails.password = "";
      $scope.edituserdetails.confirmpassword = "";
    }, function myError(response) {
      $scope.edituserdetails = response.data.userRolles;
    });

    //    	console.log(usersid);
  }


  $scope.getExistingUserValidateFunction = function(userName) {

    $http({
      method: "GET",
      url: "/containers/validateUser",
      params: {
        userName: userName
      }
    }).then(function mySucces(response) {
      var test = response.data.ExistingUserStatus
      console.log("ddddd" + test);
      return test;

    }, function myError(response) {
      //    	  return response.data.ExistingUserStatus;
    });

  }


  $scope.changePassword = function() {
    console.log("ddddd" + $scope.edituserdetails.activeuser);
    if ($scope.edituserdetails.activeuser) {
      activeuserstatus = 'Y';
    } else {
      activeuserstatus = 'N';
    }
    console.log("ccccc" + activeuserstatus);
    $http({
        method: "POST",
        url: "/containers/registrationuser",
        data: {
          "email": $scope.edituserdetails.email,
          "username": $scope.username,
          "password": $scope.edituserdetails.password,
          "id": $scope.edituserdetails.id,
          "role": $scope.edituserdetails.role,
          "userstatus": activeuserstatus


        }

      })
      .success(function(data) {
        $timeout(function() {
          $scope.msgType = false;
        }, 3000);
        $scope.theform.$setPristine();
        if (data.errorList.length > 0) {
          $scope.fieldErrorList = data.errorList;
          $scope.msgType = 'Error';
        } else {
          $scope.msgType = 'Success';
          $scope.getAllTableData();
        }

        $scope.theform.$setPristine();
        //					document.body.scrollTop = document.documentElement.scrollTop = 0;



        //                $scope.resetFunction();

      });



    // Posting data to php file
  }

  /* form.$setPristine = function() {
	    $animate.setClass(element, PRISTINE_CLASS, DIRTY_CLASS + ' ' + SUBMITTED_CLASS);
	    form.$dirty = false;
	    form.$pristine = true;
	    form.$submitted = false;
	    forEach(controls, function(control) {
	      control.$setPristine();
	    });
	  };*/

  $scope.saveUserFunction = function() {
    console.log("ddddd" + $scope.edituserdetails.activeuser);
    if ($scope.edituserdetails.activeuser) {
      activeuserstatus = 'Y';
    } else {
      activeuserstatus = 'N';
    }
    console.log("ccccc" + activeuserstatus);
    $http({
        method: "POST",
        url: "/containers/registrationuser",
        data: {
          "email": $scope.edituserdetails.email,
          "username": $scope.username,
          "password": $scope.edituserdetails.password,
          "id": $scope.edituserdetails.id,
          "role": $scope.edituserdetails.role,
          "userstatus": activeuserstatus


        }

      })
      .success(function(data) {
        console.log($scope.theform);
        if (data.errorList.length > 0) {
          $scope.fieldErrorList = data.errorList;
          $scope.msgType = 'Error';
          $scope.theform.$setPristine();
        } else {
          $scope.msgType = 'Success';
          // $scope.edituserdetails = {};
          $scope.resetFunction();
          $scope.getAllTableData();
          $timeout(function() {
            $scope.msgType = false;
          }, 3000);
          $scope.theform.$setPristine();
        }


        //					document.body.scrollTop = document.documentElement.scrollTop = 0;



        $scope.resetFunction();
        $scope.theform.$setPristine();
      });



    // Posting data to php file
  }


  $scope.resetFunction = function() {
    $scope.edituserdetails = {};
    $scope.username = '';
    $scope.edituserdetails.role = $scope.userAllRolles[0];
    $scope.theform.$setPristine();
  }

  $scope.checkPwd = function() {

    var str = document.getElementById('pw').value;
    if (str.length < 6) {
      alert("too_short");
      return ("too_short");
    } else if (str.length > 50) {
      alert("too_long");
      return ("too_long");
    } else if (str.search(/\d/) == -1) {
      alert("no_num");
      return ("no_num");
    } else if (str.search(/[a-zA-Z]/) == -1) {
      alert("no_letter");
      return ("no_letter");
    } else if (str.search(/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$/) != -1) {
      alert("bad_char");
      return ("bad_char");
    }
    alert("oukey!!");
    return ("ok");
  }


  $scope.changePasswordFucntion = function(username) {
    console.log(username);

    $http({
        method: "POST",
        url: "/containers/changePassword",
        data: {
          "password": $scope.edituserdetails.password,
          "username": username,
          "curruntPassword": $scope.edituserdetails.curruntpassword,
          "passwordConfirm": $scope.edituserdetails.confirmpassword

        }

      })
      .success(function(data) {
        $timeout(function() {
          $scope.msgType = false;
        }, 3000);
        $scope.theform.$setPristine();
        if (data.errorList.length > 0) {
          $scope.fieldErrorList = data.errorList;
          $scope.msgType = 'Error';
        } else {
          $scope.msgType = 'Success';
          $scope.getAllTableData();
        }

        $scope.theform.$setPristine();


      });
  }

  $scope.getAllRolesDetails = function() {

    $http({
      method: "GET",
      url: "/containers/getUserAlRolles"
    }).then(function mySucces(response) {
      //	 console.log(response.data.userAllRolles);
      $scope.userAllRolles = response.data.userAllRolles;
      $scope.edituserdetails = response.data.userAllRolles;
      $scope.edituserdetails.role = response.data.userAllRolles[0];

    }, function myError(response) {
      //	console.log(response.data.userAllRolles);
      $scope.userAllRolles = response.data.userAllRolles;
    });

  }




})
app.directive("passwordVerify", function() {
  return {
    require: "ngModel",
    scope: {
      passwordVerify: '='
    },
    link: function(scope, element, attrs, myCtrl) {
      scope.$watch(function() {
        var combined;

        if (scope.passwordVerify || myCtrl.$viewValue) {
          combined = scope.passwordVerify + '_' + myCtrl.$viewValue;
        }
        return combined;
      }, function(value) {
        if (value) {
          myCtrl.$parsers.unshift(function(viewValue) {
            var origin = scope.passwordVerify;
            if (origin !== viewValue) {
              myCtrl.$setValidity("passwordVerify", false);
              return undefined;
            } else {
              myCtrl.$setValidity("passwordVerify", true);
              return viewValue;
            }
          });
        }
      });
    }
  };
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

1 个答案:

答案 0 :(得分:0)

var app = angular.module("myApp");

以上代码不会创建名为myApp的模块,而只是引用现有模块。如果你还没有创建模块,那么错误就会抛出你提到的那个。

要创建模块,请执行此操作。

angular.module('myApp', []);

请阅读以下讨论以了解更多详情:

Meaning of the empty array in angularJS module declaration