I'm using UI-Router in my angular app. I'm also running multiple staged resolves. Let me explain. I want the first resolve to take place, once the promise is returned I then want to activate the second resolve. Here is my solution so far.
.state('tab.profile', {
url: '/profile',
reload: true,
cache: false,
views: {
'tab-profile': {
templateUrl: 'templates/tabs/profile.html',
controller: 'ProfileController as profile',
resolve: {
signedInUser: function (UserRecord) {
return UserRecord.retrieve( )
},
currentUser: function (signedInUser, User) {
//signedInUser is returned as null
if (signedInUser) {
return User.show({id: signedInUser.user_id}).$promise;
} else {
return false;
}
}
}
}
}
})
Here is my UserRecord.retrieve
method.
function retrieve() {
var q = $q.defer();
var query = 'SELECT user_credentials, user_id FROM Users;';
$ionicPlatform.ready(function (){
$cordovaSQLite.execute(db, query).then(function(res) {
if (res.rows.length > 0) {
console.log("found user");
console.log(JSON.stringify(res));
q.resolve(res.rows[0]);
} else {
console.log("no rows found");
q.resolve(false);
}
}, function (err) {
q.reject(err);
});
});
return q.promise;
}
The problem is that the first resolve coming in is returned as null. I'm not entirely sure what's wrong or what step I'm missing.