ngUpgraders / ng-forward

The default solution for those that want to write Angular 2.x style code in Angular 1.x
411 stars 36 forks source link

Implement ng2 basic lifecycle hooks #119

Closed DcsMarcRemolt closed 8 years ago

DcsMarcRemolt commented 8 years ago

As the old pr #41 is back from the es6 days - here is my second try as we really need these callbacks in our project and I finally want to just npm install this lib.

timkindberg commented 8 years ago

Thanks.

I think ngOnViewInit and ngOnDestroy are both in the right place, but I wonder about ngOnInit. Per this doc: https://angular.io/docs/ts/latest/api/core/OnInit-interface.html, it says:

Implement this interface to execute custom initialization logic after your directive's data-bound properties have been initialized.

But due to bug #81, I'm not 100% sure that data-bound properties (aka Inputs) will be ready by the time this hook is called. It might. I would need you to check in both TypeScript and Babel compilers.

So to get this merged:

  1. Check that data-bound properties are indeed initialized in both babel and typescript in the ngOnInit hook
  2. Write tests
  3. Write docs in the API.md
  4. Change commit message to match existing commits

Otherwise I do plan to work on this story when I get back into things. So maybe another month tops if you leave it to us.

timkindberg commented 8 years ago

related to https://github.com/ngUpgraders/ng-forward/issues/72

timkindberg commented 8 years ago

I think I'm going to pick this up. I'll certainly use what you've got here, but I'll take care to add the other required stuff (tests, docs) as well as maybe do onChange as well.

timkindberg commented 8 years ago

Added those three lifecycle hooks. Only code that I had to modify of yours was the After View Init.