Im developing Ionic cordova application for the first time watching tutorials. im now almost developed my app. and i got this problem i cant solve. that i want to pass variable from one funtion to another function.
Here is the Main code that generate the Value
$scope.ajaxLogin = function(){
$scope.show();
var fn = document.getElementById("username").value;
var pw = document.getElementById("password").value;
$http({
url: "myurl",
method: "POST",
data: { username: fn, password: pw },
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data, status, headers, config) {
if(status == 200) {
var loginid = 1; // i want to make available in other functions as well.
//otherfunction(loginid) i tried something like this. but i dont want to call the function here. i want to call it only if button is clicked. when button is Onclick that loginid should be in that function as well
if(loginid != 0){
$state.go('app.profile',{mainid:loginid}); // i also now trying like this but dont know how to catch this parameter in the other function. can anyone send me link to refer it. i cant find online
}else{
$scope.hide();
$scope.showAlertError();
}
}
})
error(function(data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
$scope.showAlertNetwork();
$scope.hide();
});
};
i want to simple do somthing like this
.controller('AppCtrl', function($scope, $ionicPopup, $timeout, $ionicModal, $state, $http, $ionicLoading) {
var loginid;// globally Defined
$scope.ajaxLogin = function(){
loginid = 1;
}
$scope.myInfo = function(){
alert(loginid);
}
});
then i can click button anytime and myInfo function gives 1 instead of undefined
Please some one can help me. if you want i can describe how my app works. its simple app that retrive id after user login to the application. loginid
will be the id in database table. and it will be ther reference to other functions to retreive the data