In my controller, I am defining a variable called tst
and assigning it a value in a function named GetOrders
. However, when I try to access the tst
variable in another function called GetTotalValueOfProducts
, it is returning as undefined without a value. This is the code snippet I am using:
<script>
app.controller('OrderController', function ($scope, $http) {
$scope.quantity = 1;
$scope.Orders = {};
var tst ;
GetOrders = function () {
$http.get('/Order/GetAllOrders').success(function (response) {
$scope.Orders = response;
//I confirm that 'tst' has a value assigned here
tst = response;
});
}
GetOrders();
GetTotalValueOfProducts = function () {
//however, at this point 'tst' is showing up as undefined
var p = tst;
}
GetTotalValueOfProducts();
});
</script>
Can you identify what might be causing this issue?