Steve Robinson
Steve Robinson

Reputation: 3939

Unable to inject restangular into AngularJS App

I have this angular app and controller modules defined as follows:

var myTasks = angular.module('myTasks', [
                                          'ngRoute',
                                          'myTasksControllers'
                                        ]);
var myTasksControllers = angular.module('myTasksControllers',[]);

I also have:

    <script src="js/lib/angular.min.js"></script>
    <script src="js/lib/angular-route.min.js"></script>
    <script src="js/lib/lodash.min.js"></script>
    <script src="js/lib/restangular.min.js"></script>
    <script src="js/app.js"></script>

And I am trying to inject rectangular into my controller like so:

myTasksControllers.controller('ProjectsController', ['$scope','rectangular',
  function ($scope, Rectangular) {
    ...
    ...
  }
]);

But it keeps telling module not defined or something. To be precise:

Error: [$injector:unpr] http://errors.angularjs.org/1.2.3/$injector/unpr?p0=rectangularProvider%20%3C-%20rectangular
    at Error (<anonymous>)

Rectangular: https://github.com/mgonto/restangular#how-do-i-add-this-to-my-project

Upvotes: 1

Views: 2824

Answers (1)

gustavohenke
gustavohenke

Reputation: 41440

You have to inject restangular module into your myTasks module first. Like this:

var myTasks = angular.module('myTasks', [
                                      'restangular',
                                      'ngRoute',
                                      'myTasksControllers'
                                    ]);

Than, you have to inject Restangular into your controller:

myTasksControllers.controller('ProjectsController', ['$scope','Restangular',
  function ($scope, Restangular) {
    ...
    ...
  }
]);

P.S.: Note that you have spelled it "rectangular" in your question :)

Upvotes: 4

Related Questions