Hi,

I am trying to implement an abstraction over angular 2 life-cycle methods 
to make it any up-gradation easy in future. 
Idea is to create a BaseComponent class which will implement angular2 
provided lifecycle methods and my other component will extend this class 
and override existing methods of BaseComponent for their purpose.

So, needed  few suggestions on,
1. what would be the better way to implement this to avoid unnecessary 
confusion regarding component lifecycle management.
2. Can @component decorator be also overridden as other methods and 
@BaseComponent can be used in place of @component in my other derived 
components.
3. Is creating custom decorator @BaseComponent a good idea if it is not 
inherently provided in angular2 (As I have read in many forums)

Dummy code which I want to implement:
import { Component, OnInit } from '@angular/core';

@Component{(

)}
export class BaseComponent implements OnInit {
private componentId :any;

constructor(){

}
ngOnInit(){
this.initialize();
}

ngOndestroy(){
this.destroy();
}
/**
* initilize
*/
public initialize() {

alert("initilization in base component");
}

/**
* name
*/
public destroy() {
alert('clean up ');
}
}



import { Component, OnInit} from '@angular/core'; 
import {BaseComponent} from '../base-component/basecomponent';

@BaseComponent({
selector: 'my-comp',
templateUrl: './my-comp.component.html',
styleUrls: ['./my-comp.component.css']
})
export class MyCompComponent extends BaseComponent {

constructor() { 
super();
}

//Base class method
initialize(){
super.initialize(); // just to perform basic init task of base component 
// other init tasks for this component can come here.
}
destroy(){
super.initialize(); // just to perform basic cleanup task of base component 
// other cleanup tasks for this component can come here.
}

}

-- 
You received this message because you are subscribed to the Google Groups 
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to