Strangely, the $rootScope.user
variable in my resolve function is not fully assigned with data before the view.html
template loads.
Most of the time, when I use {{ $root.user.uid }}
in my template, I can see the variable data, but occasionally it does not display.
I'm puzzled as to why this issue is occurring because shouldn't a resolve function run BEFORE the template loads?
Does anyone have any insights into why this might be happening?
NOTE: When I include a console.log($rootScope.user.uid)
before deferred.resolve();
, it always shows up in the console, yet the variable doesn't appear in the template.
.factory('Auth', function($http, $state, $q, $rootScope) {
var factory = {workflowItemCheck: workflowItemCheck };
return factory;
function workflowItemCheck(workflow_id) { return $http.post('/auth/workflow', {workflow_id:workflow_id}); }
})
.config(function($stateProvider, $urlRouterProvider, $locationProvider) {
var workflow_item_auth = ['$q', 'Auth', '$rootScope', '$stateParams', function ($q, Auth, $rootScope, $stateParams) {
var deferred = $q.defer();
Auth.workflowItemCheck($stateParams.workflow_id).then(function(data){
$rootScope.user = { uid: data.data.uid };
deferred.resolve();
}, function(){ deferred.reject(); });
return deferred.promise;
}];
$stateProvider.state(
'workflow2.view', {
url: '/:workflow_id/view',
templateUrl: 'pages/templates/workflow/view.html',
},
controller: 'workflow.view',
resolve: { authenticated: workflow_item_auth }
})
})