0

I'm pretty new to Angular JS, but I was making a service to get information from a JSON:

This is the service code:

var staffServices = angular.module('staffServices', ['ngResource']);

staffServices.factory('Staff', function($resource){
return $resource('/api/staff/1', {}, {
 query: {method:'GET', params: {}, isArray:false}
});
});

Controller

staffApp.controller('StaffCtrl', function($scope, Staff) {
Staff.query(function(data) {
      console.log(data);
      $scope.staff = data;
      console.log(staff);
  });

However, when I run the app, I'm able to see the "data" as an Object but I'm not able to asign it to the scope variable, I get the following "Error: staff is not defined".

Thanks for all your answers !

3
  • What is the line that gives you the error? Commented Apr 23, 2014 at 0:52
  • 3
    should be console.log($scope.staff); Commented Apr 23, 2014 at 0:53
  • @klode Put that in a formal answer; I think you nailed it. Commented Apr 23, 2014 at 1:11

1 Answer 1

4

Instead of

console.log(staff); // this prints the var staff, which is undefined

should be

console.log($scope.staff); // this prints the staff property of $scope
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.