0

I have this small issue where I am calling a service method in one function, and then trying to use the values from that function in another function (Both functions are in the same controller).

But when calling the values it says they are undefined.

the bottom coding is basically what I want to achieve not my real coding.

app.controller('Ctrl', function($scope)
{
     $scope.a = function()            // a function calling service data
     {
       $scope.value1 = array[];       //array[] list of all data called
       console.log(value[0].item1);   // value is defined
     }

     $scope.b = funtion(value1)
     {
       console.log(value1[0].item1);  // returns undefined
     }
)};

As shown in function a the value is defined but not in function b how do I keep the same value of item1 when calling it from another function?

10
  • Where have you defined value ? Commented Apr 5, 2016 at 9:41
  • don't I define it with $scope.value1 = array[]; @RayonDabre Commented Apr 5, 2016 at 9:43
  • 1
    then you should use $scope.value1 not just value1 in your console.log Commented Apr 5, 2016 at 9:43
  • the code you have posted already has some mistakes, like value is not defined, you are defining value1 then using value. Also show us how you are calling the function b, if you dont pass the array as parameter it will say undefined Commented Apr 5, 2016 at 9:44
  • value seems a global variable whereas value1 is a scope variable.. Commented Apr 5, 2016 at 9:44

1 Answer 1

2

Do $scope.value[0].item1
since the array value is in the $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.