I am trying to do promise chaining, but I am getting undefined
for a part in my chain and I am unsure why. The issue seems to be when I am using serviceFactory.GetProjectManager()
. When I return that it doesn't seem to be returning a promise, but instead automatically goes into the next .then()
with a resolved value of undefined
.
If GetProjectManager
returns a string and I return that from the function call won't it wrap it in a promise and be passed to the next promise chain?
dataFactory.GetProject()
.then(function(result){
return result.Response.ProjectId;
}).then(function(projectId){
return serviceFactory.GetProjectManager(projectId);
})
.then(function(result){
//GET UNDEFINED HERE <---------
})
.catch(function(error){
});
If I write the code like below, then it will return the right value in the callback, but I do not want to use callbacks I want to use flattened promise chaining.
dataFactory.GetProject()
.then(function(result){
return result.Response.ProjectId;
}).then(function(projectId){
serviceFactory.GetProjectManager(projectId
,function(result){
//Returns Project Manager Here <----
}
,function(error){
});
})
.catch(function(error){
});