Reputation: 126
I have 2 functions
, say A() and B().
I want to call function B()
after the function A()
execution is completed.
and I dont want to write the the function B()
calling inside the definition of function A()
, because function A()
is used in other modules too and that take unnecessary.
I am trying to call function A() first and then once it is done then call function B()
. because function B()
uses function A() $scope variable
I use .then()
but its giving error .then() undefined
something.
I called function B()
inside function A() that works but i don't want that way.
$scope.fetchApplicantData(); //function A()
$scope.fetchMobileMessages($scope.ApplicantMicroDetails.AD_I_PASTEMP_RESI_CONTACT_NO); //function B()
I am expecting to call function A()
first once it is done call the function B()
. because function B()
uses function A()
variable, but is don't want to call function b()
inside the definition in function A()
Upvotes: 1
Views: 112
Reputation: 53
You can use Promises like this:
var promise1 = new Promise(function(resolve, reject) {
setTimeout(function() {
resolve('foo');
}, 300);
});
promise1.then(function(value) {
console.log(value);
// expected output: "foo"
});
console.log(promise1);
Upvotes: 2