I have defined a function in my controller which calls a rest web-service in AngularJs. I need to assign the value returned by the function to a variable. The function may be called many times with different parameters and assign the value returned to different variables.
The function in my controller takes a parameter, which in turn is then passed to the web-service.
function disableBlockFn(blocKName) {
var data = {
formId: vm.formId,
blockId: blocKName,
statusId: vm.statusId,
roleId: vm.roleId
}
roleService.displayBlock(data).then(function (data) {
return data[0];
});
}
When i assign the value of the aboved function to a variable and print it on the console, i get 'Undefined'.
vm.pilot = vm.disableBlockFn('pilot_mpr_qualite_1');
console.log('pilot ', vm.pilot);
vm.pilot_ang = vm.disableBlockFn('pilot_mpr_qualite_ang');
console.log('pilot ', vm.pilot_ang);
Function to request WS
function displayBlock(objBlock) {
var defer = $q.defer();
$http({
method: 'GET',
url: config.urlPath + 'api/block/block'
}).then(function (data) {
var results = data;
defer.resolve(results.data.data);
}, function (data, status) {
defer.reject({
data: data,
status: status
});
});
return defer.promise;
}