質問

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/');
})
役に立ちましたか?

解決

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

 <script src="https://cdn of underscore"></script>

他のヒント

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

You need to add a reference of underscore.js in your html file. You can use following cdn path:

<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js"></script>

Might be, you should need to add following .js files:-

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-resource.js">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.8/angular-route.js">
</script> 
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min.js">
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/restangular/1.5.1/restangular.js">
</script>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top