How can I call an Angular function synchronously to get the result outside of Angular framework:
From Outside Angular: I am attempting to invoke a controller's function in Angular to save data using $http, and then utilize the saving result for subsequent steps from outside the Angular scope.
result = angular.element(divcurrency).scope().$apply('saveAll()');
if (result === "valid")
{
....
}
The controller function "saveAll" is as follows:
this.saveAll = function ()
{
var task = $q.defer();
$http.post(RESTUrl, $scope.dataToSave).then(function (response) {
task.resolve(response.data);
return response.data;
}, function (response) {
console.log(response.data);
task.reject(response.data);
return response.error;
});
return task.promise;
}
However, this function is executed asynchronously and the returned result cannot be seen. I am uncertain whether I can use the promise from outside the Angular framework. I understand that Angular recommends using asynchronous processes, but in this particular situation, I need to wait for the result to be used outside of Angular. Any assistance on this matter would be greatly appreciated.