0

on the following jsFiddle i demonstrate a problem that makes me ponder. It stems from the need to send a system wide event to all scopes, telling them that the system has finished bootstrapping. In order to do that, i got the rootScope after bootstrapping, and called its evalAsync. Alas! its not executing.

see here: http://jsfiddle.net/cusrC/8/

angular.element(document).ready(function() {
angular.bootstrap(body, ['app']);
var ngInjector = angular.injector(['ng']);

var rootScope = ngInjector.get('$rootScope');
var x = rootScope.$eval(function(scope) {   
        console.log('in eval');
        scope.$broadcast('onLoad'); 
        scope.$evalAsync(function(scope) {  
            console.log('in evalAsync');
            scope.$broadcast('onLoad'); 
        });
    });
console.log('x',x);
console.log('after');
});

many thanks for any idea or thought Lior

2 Answers 2

3

Since your code is running "outside" of Angular, you'll need to call rootScope.$digest() at the end of your sample code to cause a digest cycle to run. Then the expression inside the $evalAsync() will be evaluated/executed.

Sign up to request clarification or add additional context in comments.

Comments

2

Mark is right about calling the $digest function, but there's one more thing: you're not getting the right root scope.

angular.bootstrap returns the injector for the modules, which already pulls in the 'ng' module.

Here's your fiddle, modified.

1 Comment

thanks @satchmorun. this solves it. however the issue is a bit deeper. I use templateUrls, and i see now that the link functions are delayed until all the partials are fetched from the server. Since $on listener registration happens during link function executions, any event broadcasting prior to that execution will not get to the $on's. not sure yet how to solve but FYI

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.