4

I'm learning Angular and I'm trying to include Restangular this way:

var app = angular.module('myapp',['restangular']);
app.controller('UsersController', ['$scope', function ($scope, Restangular) {
   ...

Then I'm using Restangular like this:

var data = Restangular.all('someurl');

Here I get an error: Restangular is undefined. According to the documentation, this should have been simple:

// Add Restangular as a dependency to your app
angular.module('your-app', ['restangular']);

// Inject Restangular into your controller
angular.module('your-app').controller('MainCtrl', function($scope, Restangular) {
  // ...
});

However I am unable to get it to work. What gives?

2 Answers 2

12

You're using the bracket notation for your controller, but you forgot to add Restangular to the list of dependencies:

['$scope', 'Restangular', function ($scope, Restangular) {...}]

This article has more information on Angular and minification. Search for "A note on minification”.

Sign up to request clarification or add additional context in comments.

2 Comments

I tried this also, but this seemed to break something else (a custom filter). I'll try this again and look into it a bit more.
Ok, this is the correct way to do this, my code is wasn't working for other reasons, so I was asking the wrong questions here really.
-3

That looks correct, just make sure you've added the import of Restangular to your html file

<script type="text/javascript" src="http://cdn.jsdelivr.net/restangular/1.1.3/restangular.js"></script>

They also mention it requires lodash or underscore.js so maybe make sure you're loading those as well

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.