У меня есть контроллер, как показано ниже:
.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 () {
}
})
У меня есть функция window.onmessage, и внутри нее у меня есть http-запрос GET, который получает данные для меня.Я пытаюсь получить его, присвоив его значение переменной «allForms», чтобы я мог использовать его в другой функции внутри контроллера, однако он получает неопределенное значение. Как я могу получить его?Заранее спасибо.