I'm working with AngularJS and I have two API methods in my factory. I've been trying to call these two methods one after the other, but it's not functioning as expected.
The desired sequence is to first execute test1 followed by test2.
Below is the code snippet from the controller:
app.controller("Test").function($scope, factoryMethod) {
factoryMethod.test1().then(function(data) {
console.log(data);
console.log("test1");
}).then(factoryMethod.test2().then(function(data) {
console.log(data);
console.log("test2");
})).catch(function(data) {
alert(data);
});
}
And here's the relevant part from the factory:
app.factory("factoryMethod", function (){
//code for test1
//code for test2
});
At the moment, the console output shows: 1. test2 2. test1
The expected behavior is to log test1 first, followed by test2.