Wondered what's the best way to detect the finish of page loading/bootstrapping, when all directives done compiling/linking.
Any event already there? Should I overload the bootstrap function?
Wondered what's the best way to detect the finish of page loading/bootstrapping, when all directives done compiling/linking.
Any event already there? Should I overload the bootstrap function?
I had a fragment that was getting loaded-in after/by the main partial that came in via routing.
I needed to run a function after that subpartial loaded and I didn't want to write a new directive and figured out you could use a cheeky
ngIf
Controller of parent partial:
HTML of subpartial
may be i can help you by this example
In the custom fancybox I show contents with interpolated values.
in the service, in the "open" fancybox method, i do
the $compile returns compiled data. you can check the compiled data
According to the Angular team and this Github issue:
Based on this, it seems this is currently not possible to do in a reliable way, otherwise Angular would have provided the event out of the box.
Bootstrapping the app implies running the digest cycle on the root scope, and there is also not a digest cycle finished event.
According to the Angular 2 design docs:
According to this, the fact that this is not possible is one the reasons why the decision was taken to go for a rewrite in Angular 2.
If you want to generate JS with server-side data (JSP, PHP) you could add your logic to a service, that will be loaded automatically when your controller is loaded.
Additionally, if you want to react when all directives are done compiling/linking, you could add the appropriate proposed solutions above in the initialization logic.
If you don't use ngRoute module, i.e. you don't have $viewContentLoaded event.
You can use another directive method:
Accordingly to trusktr's answer it has lowest priority. Plus $timeout will cause Angular to run through an entire event loop before callback execution.
$rootScope used, because it allow to place directive in any scope of the application and notify only necessary listeners.
If you are using Angular UI Router, you can listen for the
$viewContentLoaded
event."$viewContentLoaded - fired once the view is loaded, after the DOM is rendered. The '$scope' of the view emits the event." - Link