1

I have some computations in myapp.config functions. They are performed when the page is loaded (or bootstrapped). I need to repeat these computations after that (e.g. after clicking a button or authentication ;-)).

So what I need is

  1. Execute myapp.config functions while loading the page. That is performed natively by Angular.
  2. The user clicks the button (that is just an example).
  3. Execute myapp.config functions again. how can I do that?

$router.reload() (or $state from ui-router) reloads controllers, config functions will not be executed again.

$window.location.reload() will do that but the page will be reloaded, I do not want to reload the page (i.e. the user should not see that I'm hacking around).

Manual bootstrapping may be what I need but I'm not sure how to use it for this. I cannot execute the following code twice (for the first load and after the user clicked the button) because of the error "the element is already bootstrapped".

angular.element(document).ready(function() {
    angular.bootstrap(document, ['myapp']);
});

Any ideas how I can execute config code twice?

9
  • use $state.reload() from ui.router Commented Oct 30, 2016 at 13:24
  • Did you read my question? I wrote it reloads just controllers, my config functions will not be executed. Commented Oct 30, 2016 at 13:26
  • Config phase only runs once per page load. Please provide more details about what these computations do. Commented Oct 30, 2016 at 13:33
  • @charlietfl I initialize ng-admin table inside config. ng-admin users have to initialize all tables inside config. But I need to provide users with different tables according to their roles. So after authentication I want to change ng-admin table configurations. Reloading Angular application seems to be the easiest option here. Commented Oct 30, 2016 at 13:36
  • 1
    Re-bootstrapping is hacky and may cause side effects, page reloading is cleaner solution. It depends on whether you want an answer that suits your question or not. The fact that it the question isn't 'polluted' doesn't make it good because it doesn't reflect your case. The code in the question would help. Commented Oct 30, 2016 at 14:09

0

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.