Restangular errors when added to a project: `Error: $injector:modulerr`

Issue

When adding Restangular to a project it throws sn [Error: $injector:modulerr] error. I’ve ensured this error isn’t being thrown by one of my own modules. I’ve followed the docs on setting it up and I’m pulling from their CDN. If Restangular is removed as a dependency it works.

Reproduced below:

js:

angular.module('app', ['restangular'])
.controller('Main', function(){
    this.msg = 'Hello World'
})

html:

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.3.1/restangular.js"></script>

<main ng-app="app" ng-controller="Main as vm">
  <h1>{{vm.msg}}</h1>
</main>

Reproduced in a codepen.

Solution

So you’re missing an _.js dependency. I was able to update your CodePen, and made your code

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/restangular/1.3.1/restangular.js"></script>
<main ng-app="app" ng-controller="Main as vm">
    <h1>{{vm.msg}}</h1>
</main>

just to prove no magic here’s a plunker
http://plnkr.co/edit/OvUefl8x0H6dvZs2B0ls?p=preview

Answered By – mikeswright49

Answer Checked By – Timothy Miller (AngularFixing Admin)

Leave a Reply

Your email address will not be published.