I have the following code:
authService.authenticate()
.then(function (user) {
return Task.all({user: user})
})
.then(function (tasks) {
// How to access user object here?
})
Is there some built-in way to pass user
object to the second then
function without doing something like this:
var user2 = null;
authService.authenticate()
.then(function (user) {
user2 = user
return Task.all({user: user})
})
.then(function (tasks) {
// Use user2 here
})
or this:
authService.authenticate()
.then(function (user) {
var defer = $q.defer()
Task.all({user: user}).then(function (tasks) {
return defer.resolve(user, tasks)
})
return defer.promise
})
.then(function (user, tasks) {
// Use user2 here
})
or nesting them by calling the second then
directly on Task.all
(this way I'd have user
object available via closure)?
Nesting them is exactly what I'm trying to avoid.