-->

Error ngRoute is not available

2019-09-08 16:13发布

问题:

there is my error in console

Error: [$injector:nomod] Module 'ngRoute' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

this is my index.html header :

    <script src="scripts/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="scripts/libs/bootstrap.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.js" type="text/javascript"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular-route.js" type="javascript"></script>

    <script src="scripts/app.js" type="text/javascript"></script>
</head>

this is my app.js :

var app = angular.module('myapp', ['ngRoute']);

app.config(function($routeProvider){
$routeProvider
    .when('/queueManager', {
        templateUrl: '/templates/page/queueManager.html',
        controller: 'QCtrl'
    });
});

app.controller('QCtrl',['$http','$interval','$scope', function($http, $interval,$scope){
  this.queues = queue;
  var store = this;
  store.queues = [];
  var queue = [];

  $http.get('/queue/info').success(function(data) {
    store.queues = data;
  });
});

And this is my routes.js :

angular.module("myapp", ['ngRoute'])
.config(function($routeProvider){
    $routeProvider.when('/queueManager', {
        templateUrl: '/templates/page/queueManager.html'
    })
});

In dev tools from chrome, files appears as loaded, and it seems that i spelled it right... An I still get the same error as mentioned before. Every time i search on stackoverflow, it's the same answer check if you added it in your html... Have you some solution about my problem ?

Edit : Added app.config in app.js and changed routes module name to my app. And added edit

Thank you

回答1:

You need to add your "AchApp" module as a dependency of the 'myapp' module.

So your app.js would look like:

var app = angular.module('myapp', ['ngRoute', "AchApp"]);

app.controller('QCtrl',['$http','$interval','$scope', function($http, $interval,$scope){
  this.queues = queue;
  var store = this;
  store.queues = [];
  var queue = [];

  $http.get('/queue/info').success(function(data) {
    store.queues = data;
  });
});


回答2:

I finally found my mistake....

My script type was "javascript" and not "text/javascript". Best mistake ever ...

Thanks for your answer by the way.