angularjs - $resource error even after adding dependency to ngResource -
i trying display data in angular app using $resource, mongolab. added dependency ngresource in module. still says unknown provider. missing point here?
'$resource not defined'
note: when factory name not correct, getting error: unknown provider: employeesprovider <- employees
code
<html> <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular-resource.js"></script> <script type="text/javascript"> //defining module var app = angular.module('myapp', ['ngresource']); //defining factory app.factory('employees', function () { return $resource('https://api.mlab.com/api/1/databases/humanresource/collections/employees', {apikey: 'removedmykeyforpostinginso'} ); }); //defining controller app.controller('mycontroller', function ($scope, employees) { $scope.countries = employees.query(); }); </script> </head> <body ng-app="myapp"> <div ng-controller="mycontroller"> <ul> <li ng-repeat = "objcountry in countries" > {{objcountry.name}} </li> </ul> </div> </body> </html>
json mongolab
[ { "_id" : { "$oid" : "57044f95e4b0427faa38585f"} , "name" : "lijo" , "age" : "30"} ]
from angulajs documentation, recommended way of declaring factories is:
angular.module('mymodule', []) .factory('serviceid', ['depservice', function(depservice) { // ... }])
i corrected factory code below, injecting $resource:
app.factory('employees', function ($resource) { return $resource('https://api.mlab.com/api/1/databases/humanresource/collections/employees', {apikey: 'jjbaltz26vuirgzuqetxh480jm0q9k6p'} ); });
references: