My config looks like the following:
app.config(function ($routeProvider) {
$routeProvider
...
.when('/project/:slug', {
templateUrl: 'partials/plaintasks-part.php',
controller: 'ProjectCtrl',
resolve : {
projectDetail : ProjectCtrl.loadProject
}
})
...
});
And loadProject is as follows:
// Project controller
var ProjectCtrl = app.controller('ProjectCtrl', ...);
ProjectCtrl.loadProject = function( $q, Tasks, $route ){
var defer = $q.defer();
var slug = $route.current.params.slug;
// Tasks.getProjectBySlug() is where I have implemented the http request to get the data from server
var project = Tasks.getProjectBySlug( slug );
var tasks = Tasks.getProjectTasks( project.id );
defer.resolve({
tasks : tasks,
project : project
});
return defer.promise;
}
Now the problem is, it doesn't wait for the projects and tasks to be fetched from the server and simply shows the view which I don't want unless the data is fetched from the server. Can anyone please tell me, what am I doing wrong here? Why doesn't it wait for the data to be fetched although I have implemented the resolve in my route?