Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS 1.2 $injector:modulerr

When using angular 1.2 instead of 1.07 the following piece of code is not valid anymore, why?

'use strict';  var app = angular.module('myapp', []);  app.config(['$routeProvider', '$locationProvider',     function($routeProvider, $locationProvider) {         $locationProvider.html5Mode(true);         $routeProvider.         when('/', {             templateUrl: 'part.html',             controller: 'MyCtrl'         }).         otherwise({             redirectTo: '/'         });     } ]); 

the issue is in the injector configuration part (app.config):

Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.2.0rc1/$injector/modulerr?p0=muninn&p1=Error%…eapis.com%2Fajax%2Flibs%2Fangularjs%2F1.2.0rc1%2Fangular.min.js%3A31%3A252)  

If I remember correctly this issue started with angular 1.1.6.

like image 729
shoen Avatar asked Aug 17 '13 09:08

shoen


2 Answers

The problem was caused by missing inclusion of ngRoute module. Since version 1.1.6 it's a separate part:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0rc1/angular-route.min.js"></script>  var app = angular.module('myapp', ['ngRoute']); 
like image 119
shoen Avatar answered Sep 21 '22 17:09

shoen


my error disappeared by adding this '()' at the end

(function(){     var home = angular.module('home',[]);      home.controller('QuestionsController',function(){         console.log("controller initialized");         this.addPoll = function(){             console.log("inside function");         };     }); })(); 
like image 32
arp Avatar answered Sep 21 '22 17:09

arp