user1713964
user1713964

Reputation: 1249

AngularJS and resource : Unknown provider: $resourceProvider <- $resource

I'm using $resource to show a json list file and wondering why it generates an error message :

 Unknown provider: $resourceProvider <- $resource

Here's the code :

HTML :

 <div ng-app="manage">
 .....

   <div class="widget-content" ng-controller="testCtrl">
    {{test}}
   </div>

app.js

 angular.module('manage',['ngResource']);

and controller.js

 function testCtrl($scope,$resource) {
   var dataService = $resource('/users/1/test.json');
   $scope.test = dataService.get();
 }

Seems it works well on plunkr http://plnkr.co/edit/bJfJurl6Gtw3qRcn4ViW?p=preview But not on my app. I use exactly same structure.. (even on loading angular and angular-resource files order)

The only differences I can notice are angularJS version (I use 1.0.2 on my app) and of course json file.

What am I doing wrong ?

UPDATE :

I changed angular versions on plunkr. Same on both side now

Upvotes: 0

Views: 5565

Answers (1)

user1713964
user1713964

Reputation: 1249

OK just found it !! The thing is that I have 2 angular Modules in my app. On html tag I have a whole app managing Bootstrap and jQuery UI and on a specific part this module.

If we don't add ngResource on main app module, this error occurs, but then if we define this

<html ng-app="ui">
......
<div ng-app="manage">

and in Angular app.js

 angular.module('ui', ['ui.bootstrap','ui.sortable', 'ngResource']);

 angular.module('manage', ['ngResource']);

Then it works !

I couldn't find anything in Angular Docs explaining this. But overall Big Thanks to @Thomas who helped me :)

Upvotes: 2

Related Questions