Error: No module: ngRoute when trying to implement routing in angularjs

谁说我不能喝 提交于 2019-12-19 05:19:59

问题


app = angular.module("dithat", ["ngRoute", "ngResource", 'ng-rails-csrf']);
  app.config(['$routeProvider',
  function($routeProvider) {
  $routeProvider.
  when('/', {
    templateUrl: 'app/views/layouts/_user_page.html',
    controller: 'accomplishmentController'
  });
}]);

Am I missing something? Thanks!


回答1:


Have you included the angular-route.js file in your page? And are you using angular 1.2.0 - the module doesn't seem to exist prior to this.

See http://docs.angularjs.org/api/ngRoute




回答2:


Add angular-route into application.js like

in /app/assets/javascripts/application.js

//= require angular
//= require angular-resource
//= require angular-route



回答3:


Remove ngRoute from our dependency injection as you are already injecting routeProvider in config

app = angular.module("dithat", ["ngResource", 'ng-rails-csrf']);
  app.config(['$routeProvider',
  function($routeProvider) {
  $routeProvider.
  when('/', {
  templateUrl: 'app/views/layouts/_user_page.html',
  controller: 'accomplishmentController'
});
}]);


来源:https://stackoverflow.com/questions/19416575/error-no-module-ngroute-when-trying-to-implement-routing-in-angularjs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!