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?

nickolay.laptev
  • 2,253
  • 1
  • 21
  • 31
  • use $state.reload() from ui.router – Theophilus Omoregbee Oct 30 '16 at 13:24
  • Did you read my question? I wrote it reloads just controllers, my config functions will not be executed. – nickolay.laptev Oct 30 '16 at 13:26
  • Config phase only runs once per page load. Please provide more details about what these computations do. – charlietfl Oct 30 '16 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. – nickolay.laptev Oct 30 '16 at 13:36
  • Should probably use a service in combination with router resolve. No idea what `ng-admin` is. Still not enough known – charlietfl Oct 30 '16 at 13:38
  • Please, specify in the question which ng-admin code exactly you need to re-evaluate. – Estus Flask Oct 30 '16 at 13:55
  • @estus there is https://github.com/marmelab/ng-admin/issues/875 issue for that. I have no idea why that code was supposed to be working. These details do not relate to the question so I don't want to pollute it with them. – nickolay.laptev Oct 30 '16 at 13:57
  • There is a nice question - http://stackoverflow.com/questions/23973744/how-to-restart-angular-app-without-page-reload about the same but I got the error that element was already bootstrapped when trying to replace bootstrapping elements. – nickolay.laptev Oct 30 '16 at 14:04
  • 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. – Estus Flask Oct 30 '16 at 14:09

0 Answers0