Restangular: Error: Unknown provider


I want to inject Restangular in my app to communicate with via REST.

So, here I am know with an error:

Error: [$injector:unpr] Unknown provider: RestangularProvider <- Restangular <- Api

Api is my own module here. What I’m doing:

  1. Creating a main module called Dashboard
  2. Creating a submodule called API

Now I want to use Restangular, but couldn’t figure out how Angular is managing the dependencies…

Here is my sub-module where I inject Restangular:

angular.module( 'dashboard.api', ['restangular']).factory('Api', ['$http', 'Config', 'Restangular', function($http, Config, Restangular) {

My main module, Dashboard, doesn’t need to inject Restangular, right?

angular.module( 'dashboard', [ 'dashboard.api'])

How is the injection-depency working within submodules? How can I
integrate Restangular in my app?

EDIT: Source file is included:
enter image description here


Okay I found the problem and the solution.

You have to differ between restangular(the module) and Restangular the service.

First, you have to include the main module of restangular into your app:

For me, it was this (polygon is a submodule of my app:

angular.module('polygons', ['restangular']);

Then, I wanted to inject restangular into a factory of that submodule:

angular.module('polygons').factory('polygonService', ['Restangular', polygonService]);

function polygonService(Restangular) {
// ...

This works for me. Hope this helps.

Answered By – ProblemsOfSumit

Answer Checked By – Candace Johnson (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.