phpangularjsangular-ui-routerangularjs-injector

Uncaught Error: $injector:modulerr; works locally but not on server


The following code works fine in my local dev environment, but when I have the solution hosted on a server I get the following error, after using the unminified js I get the following error:

angular.js:66 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
    ReferenceError: shallowCopy is not defined

Below is the relevant code, my index.php file including all of the file and the app.js file that is injecting my directives:

index.php:

<!-- bootstrap/jquery -->
<meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;">

<script src="js/jquery/jquery-3.1.1.min.js"></script>
<script src="js/jquery/jquery-ui.min.js"></script>
<link rel="stylesheet" href="styles/jquery/jquery-ui.min.css" />

<link rel="stylesheet" href="styles/bootstrap-3.3.7-dist/css/bootstrap.css" />
<script src="styles/bootstrap-3.3.7-dist/js/bootstrap.min.js"></script>
<script src="plugins/Bootstrap-3-Typeahead-master/bootstrap3-typeahead.min.js"></script>
<!-- end bootstrap/jquery -->
<!-- custom css -->
<link rel="stylesheet" href="styles/styles.css" />
<!-- end custom css -->
<!-- favicon -->
<link rel='shortcut icon' type='image/x-icon' href='media/images/favicon.ico' />
<!-- end favicon -->

<!-- custom js -->
<script src="js/main.js"></script>
<!-- end custom js -->

<!-- angularjs -->
<script src="js/angularjs/angular.min.js"></script>
<script src="js/angularjs/angular-route.min.js"></script>
<script src="js/angularjs/angular-sanitize.js"></script>

<script src="js/app.js"></script>
<script src="js/login/login.js"></script>
<script src="js/questionnaire/questionnaire.js"></script>
<script src="js/study/study.js"></script>
<script src="js/result/result.js"></script>
<!-- end angularjs -->
<div class="row" ng-app="app" >
    <div ng-view>
    </div>
</div>

app.js:

// app.js
(function () {

  "use strict";

  // Creating the Module
  angular.module("app", ["ngRoute", "ngSanitize"])
    .config(function ($routeProvider) {
        //$location.path('/questionnaire'); //logged in already, session still active

      $routeProvider.when("/", {
        controller: "loginController",
        controllerAs: "vm",
        templateUrl: "views/login.php"
      });

      $routeProvider.when("/questionnaire/", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });

      $routeProvider.when("/questionnaire/:survey", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });

      $routeProvider.when("/study/:studyid", {
        controller: "studyController",
        controllerAs: "vm",
        templateUrl: "views/study.php"
      });

      $routeProvider.when("/result/", {
        controller: "resultController",
        controllerAs: "vm",
        templateUrl: "views/result.php"
      });

      $routeProvider.otherwise({ redirectTo: "/" });

    });

})();

Solution

  • It's probably a problem of js minification, ref https://docs.angularjs.org/guide/di#implicit-annotation

    Try the following, note the ['$routeProvider...:

    replace your code with this

    (function () {
    
      "use strict";
    
    angular.module("app", ["ngRoute", "ngSanitize"])
        .config(['$routeProvider', function ($routeProvider) {
            //$location.path('/questionnaire'); //logged in already, session still active
    
      $routeProvider.when("/", {
        controller: "loginController",
        controllerAs: "vm",
        templateUrl: "views/login.php"
      });
    
      $routeProvider.when("/questionnaire/", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });
    
      $routeProvider.when("/questionnaire/:survey", {
        controller: "questionnaireController",
        controllerAs: "vm",
        templateUrl: "views/questionnaire.php"
      });
    
      $routeProvider.when("/study/:studyid", {
        controller: "studyController",
        controllerAs: "vm",
        templateUrl: "views/study.php"
      });
    
      $routeProvider.when("/result/", {
        controller: "resultController",
        controllerAs: "vm",
        templateUrl: "views/result.php"
      });
    
      $routeProvider.otherwise({ redirectTo: "/" });
    
    }]);
    
    })();