4

I'm trying to use restangular as an adapter for rails rest api, but i can't make it work properly. I've downloaded the latest version and put the file in vendor/assets/javascripts folder. But once i try to load the app i get the following error:

Error: Unknown provider: RestangularProvider <- Restangular
    at Error (<anonymous>)
    at http://0.0.0.0:3000/assets/angular.js?body=1:2706:19
    at Object.getService [as get] (http://0.0.0.0:3000/assets/angular.js?body=1:2832:39)
    at http://0.0.0.0:3000/assets/angular.js?body=1:2711:45
    at getService (http://0.0.0.0:3000/assets/angular.js?body=1:2832:39)
    at invoke (http://0.0.0.0:3000/assets/angular.js?body=1:2850:13)
    at Object.instantiate (http://0.0.0.0:3000/assets/angular.js?body=1:2882:23)
    at http://0.0.0.0:3000/assets/angular.js?body=1:4771:24
    at http://0.0.0.0:3000/assets/angular.js?body=1:4350:17
    at forEach (http://0.0.0.0:3000/assets/angular.js?body=1:161:20) 

Here is my application.js file

//= require jquery
//= require bootstrap
//= require suggest.min
//= require angular
//= require underscore
//= require restangular
//= require angular-strap.min
//= require angular-cookies
//= require angular-resource
//= require angular/index

The app is initialized as follows:

angular.module('angularApp', [
  'ngCookies', 
  'restangular'
]);
angular.module('angularApp.services', [
  'ngResource',
  'sessionService',
  'courseService'
]);
angular.module('angularApp.resources', [
  'ngResource'
]);
angular.module('angularApp.directives', []);
angular.module('angularApp.filters', []);
angular.module('angularApp.controllers', []);

var App = angular.module('angularApp', [
  'angularApp.resources',
  'angularApp.services',
  'angularApp.directives',
  'angularApp.filters',
  'angularApp.controllers',
  '$strap.directives'
  ]);

There is also a controller which tempts to use restangular without any success

angular.module('angularApp.controllers').controller('CourseListCtrl', [
  '$scope', '$location', 'Restangular', 
  function($scope, $location, Restangular) {"use strict";
    $scope.courses = Restangular.all('courses')
}]);

What am i doing wrong? It seems i've done everything described in the restangular guide, but still don't understand the reason why it's not working.

3
  • I feel like you define angularApp twice Commented Sep 19, 2013 at 18:40
  • @apneadiving How can i check that? I've searched the project and see only one place where the app is created(I mean where all dependencies are injected). Commented Sep 19, 2013 at 18:47
  • cool, posted as an answer then Commented Sep 19, 2013 at 19:00

2 Answers 2

8

As per my comment, you're defining the module twice, the second time it overrides your restangular inclusion.

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

Comments

7

The second angular.module('angularApp'... overwrites the first one erasing the rectangular dependency.

If you need to reference the angularApp module, do it without brackets, like this:

var App = angular.module('angularApp')
  • With brackets -> module creation
  • Without brackets -> module reference

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.