I have some code like this
I have load function, it call testRequest
function.
testRequest
function call ajax service and return response.
But after testRequest
function run success, load function get undefined value
angular.module('MyApp', []).controller("AppCtrl", ['AjaxService', function(ajax) {
var l_this = this;
this.testRequest = function() {
var req = ajax.getstatus('https://testapi.io/api/nguyenthemanh2601/testangular');
req.then(function(rep) {
var arr = [];
if (rep.status == 400) {
for (i = 1; i < 10; i++) {
arr.push(rep.data + i);
}
return arr;
} else {
for (i = 1; i < 10; i++) {
arr.push(rep.data + i);
}
return arr;
}
});
};
this.load = function() {
var res = l_this.testRequest();
console.log(res);
l_this.status = res;
}
}]);
Please help!