Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
AngularJS - Delay Controller Initialization for Asynchronous Operations http://midgetontoes.com/blog/2014/04/15/angularjs-delay-controller-initialization-for-asynchronous-operations/
angular.module('controllers', ['services'])
.controller('MyCtrl', ['$scope', ($scope) ->
$scope.$watch('dataReady', (ready) ->
init() if ready
)
init = () ->
console.log('Init')
])
angular.module('services', [])
.run(['$rootScope', 'dataService', ($rootScope, dataService) ->
dataLoaded = false
$rootScope.dataReady = false
dataService.loadData().then(() ->
dataLoaded = true
)
$rootScope.$watch(() ->
dataLoaded
, (ready) ->
$rootScope.dataReady = ready
)
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment