$scope.fetchData = function (param) {
var url = param;
var thumb;
var imgid = get_numbers(url);
var hash = ("http://vimeo.com/api/v2/video/" + imgid + ".json");
$http({
method: 'GET',
url: hash
}).then(function successCallback(response) {
thumb = response.data[0].thumbnail_medium;
}, function errorCallback(response) {
console.log("Request fail");
});
return thumb;
};
function get_numbers(input) {
return input.match(/[0-9]+/g);
}
var imgthumb = $scope.fetchData("http://player.vimeo.com/video/219839519");
alert(imgthumb);
Example: when I make console.log from the variable thumb inside the then function, I can see the value of the variable, but when it returns the main function the value of the variable is undefined.