user2413453
user2413453

Reputation:

angularjs defining values with different functions

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?

Upvotes: 0

Views: 48

Answers (1)

Shubham
Shubham

Reputation: 189

Do $scope.value[0].item1
since the array value is in the $scope

Upvotes: 2

Related Questions