PrimeLens
PrimeLens

Reputation: 2697

angular 1.2 where am I declaring wrong? factory not defined

Forgive me if this is a duplicate, I've tried searching other threads but I don't see similar to this annotation.

The error : factoryGet is not defined

 var myapp = angular.module('myapp', ['ngRoute','myServices']);
 /* adds in the myServices module and its factory as a dependency */    
 myapp.controller(
   'mycontroller', 
   [
     '$scope',
     function($scope) { 
       $scope.mydata = factoryGet.query(); 
     }
   ]
 );

 myapp.config(specifyRoute);
 function specifyRoute ($routeProvider) {
   $routeProvider
     .when('/', {template: '<div>no template</div>'})
     .when('/pagea', {template: '<div>Page A</div>'})
     .when('/pageb', {template: '<div>Page B</div>'})
     .when('/pagec', {template: '<div>Page C</div>'});
 }

 // define a new module called myServices
 angular.module('myServices', ['ngResource'])
   .factory('factoryGet', function  ($resource) {
     return $resource(
       '/airports',   // server path
       { method: 'getTask', q: '*' }, // Query parameters
       {'query': { method: 'GET' }}
     );
   });

the html is pretty standard

 <div class="container">
   <a href="#" class="btn btn-default">Home</a>
   <a href="#/pagea" class="btn btn-default">Page A</a>
   <a href="#/pageb" class="btn btn-default">Page B</a>
   <a href="#/pagec" class="btn btn-default">Page C</a>
 </div>
 <div class="container" ng-controller="mycontroller">
   <div ng-view></div>
 </div>

Upvotes: 0

Views: 52

Answers (1)

Khanh TO
Khanh TO

Reputation: 48972

Try:

myapp.controller(
   'mycontroller', 
   [
     '$scope',
     'factoryGet', //declare your dependency
     function($scope,factoryGet) { //declare your dependency
       $scope.mydata = factoryGet.query(); 
     }
   ]
 );

Upvotes: 1

Related Questions