Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError: _ is not defined from restangular

I'm getting this error: Uncaught ReferenceError: _ is not defined from restangular when trying to use Restangular.

HTML

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.1/angular.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/latest/restangular.min.js"></script>
<script src="app.js"></script>
<script src="controllers.js"></script>

app.js

var contactManager = angular.module('contactManager', ['restangular'])
contactManager.config(function(RestangularProvider){
    RestangularProvider.setBaseUrl('/api/');
})
like image 991
Carlos Bergen Avatar asked Jun 24 '13 19:06

Carlos Bergen


People also ask

How do I fix uncaught ReferenceError is not defined?

Answer: Execute Code after jQuery Library has Loaded The most common reason behind the error "Uncaught ReferenceError: $ is not defined" is executing the jQuery code before the jQuery library file has loaded. Therefore make sure that you're executing the jQuery code only after jQuery library file has finished loading.

What is uncaught ReferenceError in JavaScript?

The Javascript ReferenceError occurs when referencing a variable that does not exist or has not yet been initialized in the current scope.


2 Answers

you need to add a script reference to underscore, as is a dependency

 <script src="https://cdn of underscore"></script>
like image 124
Rayweb_on Avatar answered Oct 19 '22 00:10

Rayweb_on


restangular requires underscore/lodash` to work. Just put this dependancy before your restangular script. Also read this comment on github.

like image 25
Pono Avatar answered Oct 19 '22 01:10

Pono