question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

module.run() equivalent in Angular 2

See original GitHub issue

I wonder if there’s something like angular.module().run() in Angular 2. Angular 2 doesn’t have config() and run() anymore (which is good), but I think there are still some cases where we want to execute some code, once everything inside a component is compiled. Something that is only initially executed.

I’m currently playing with the instance of ComponentRef that we get from bootstrap() a la:

bootstrap(MyComponent).then((ref) => {
  let app = ref.instance;

  app.run();
});

Whereas run() is a method that needs to be executed once everything inside MyComponent is compiled. I also tried using onAllChangesDone but it seems this is executed several times per second and not only once.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
mheverycommented, Oct 13, 2016

You can put work into the constructor of the module.

1reaction
mheverycommented, Apr 27, 2015

Use of then on ComponentRef should be the right approach.

bootstrap(MyComponent).then((ref) => {
  let app = ref.instance;

  app.run();
});

What specifically is not working?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Equivalent of $compile in Angular 2 - typescript - Stack Overflow
Angular 4 came up with ComponentFactoryResolver which equivalent to $ compile in Angular 1.0 .See my answer stackoverflow.com/questions/34784778 ...
Read more >
Upgrading from AngularJS to Angular
In a hybrid application you run both versions of Angular at the same time. That means that you need at least one module...
Read more >
Use @NgModule to Manage Dependencies in your Angular 2 ...
The Angular 2 @NgModule decorator allows for easier management of dependencies within the Angular 2 framework.
Read more >
From angular.module to ngModule - Telerik Blogs
The main organization mechanism is still the component within Angular 2 but ngModule was introduce to make organizing and connecting components ...
Read more >
How to Migrate from Angular 1.x to Angular 2 in Simple Steps
After converting code for an AngularJS module to its equivalent Angular code, it might be needed that one of the converted component is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found