I define a variable by the name tst
in controller, and i give some value in a function by the name GetOrders
, but when i get tst
in another function GetTotalValueOfProducts
it is undefined and does not have value,this is what i do:
<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;
//here i set tst, and tst has value, i checked it has value and it's not undefined
tst = response;
});
}
GetOrders();
GetTotalValueOfProducts = function () {
//but here 'tst' is undefined!!!
var p = tst;
}
GetTotalValueOfProducts();
});
</script>
What is the problem?