I want to inject a grandchild Service in the root Module like this:
providers:[MyAppTables]
My services structure is like this:
@Injectable()
export class TableBase {
protected _items: BehaviorSubject<any[]> = new BehaviorSubject([]);
public items: Observable<any[]> = this._items.asObservable();
constructor(){
this.init([]);
}
init(newItems:any[]) {
this._items.next(newItems);
}
}
@Injectable()
export class TableProducts extends TableBase {
constructor(@Inject(TableBase) __base: any ){
super();
}
init() {
super.init([{id:1,name:'A'},{id:2,name:'B'}]);
}
}
@Injectable()
export class MyAppTables{
public products: Observable<any[]>;
constructor(@Inject(TableProducts) prod: any ){
this.products = prod.items;
}
}
So far I only could make it work like this
provider:[TableBase, TableProducts, MyAppTables]
my question is: there is a better way to inject this?
Note: this example only shows 1 parent, the idea is to abstract the base code in the grandparent class, make a parent class for each table and include that service where is needed