I have a controller like below:
.controller('googleFormsCtrl', function ($scope, $http, $window) {
// SEND THE HTTP REQUEST
var url;
var allForms;
var externalWindow;
// MAKE API REQUEST for Authorization
$http.get('/api/googleAuth').then(function (response) {
url = response.data;
});
this.googleAuthentication = function () {
externalWindow = $window.open(url, "Please Sign in with Google", "width:350px,height:350px");
};
// Close Authorization and set credentials
window.onmessage = function (info) {
externalWindow.close();
// Get the CODE from the URL
var urlCode = info.data;
// Get pure code
var idx = urlCode.lastIndexOf("code=");
var code = urlCode.substring(idx + 5).replace("#","");
// Get TOKEN
$http.get('/api/googleToken?code=' + code).then(function (response) {
console.log(response.data);
allForms = response.data;
});
};
console.log("HERE IS UNDEFİNED " + allForms);
// Fill Drop Down with Forms
this.fillForms = function () {
}
})
I have a window.onmessage function and within it I have an http GET requet which retrieves data to me. I am trying to retrieve it by assigning its value to "allForms" variable so that ı can use it in another function within controller, however it retrieves undefined value.How can I retrieve it? Thanks in advance.