I want extend my provider with modules to use like classA.moduleClassB
but i can't and I don't know how import a module class object to my controller page as provider
Example(as I want):
providers/my-provider/my-provider.ts
export class MyParentClass {
//...
}
export module a {
class MyChildClass {
//...
}
}
pages/home/home.ts
import { Component } from '@angular/core';
import { MyParentClass, MyChildClass } from '../../providers/my-provider'
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [
MyParentClass,
MyChildClass
]
});
export class homePage {
constructor(public parentClass: MyParentClass, public childClass: MyChildClass) {
}
}
You can only inject classes that are marked as Injectable. Mark your classB as Injectable and then inject it in the constructor as you did.
In order to use proper dependency injection, change the access modifier to private. You can then access your classB in classA.
favorite I want extend my provider with modules to use like classA.moduleClassB but i can't and I don't know how import a module class object to my controller page as provider
Should look something like this:
providers/my-provider/my-provider.ts
import {Injectable} from "@angular/core";
@Injectable()
export class MyParentClass {
//...
}
export module a {
@Injectable()
export class MyChildClass {
//...
}
}
pages/home/home.ts
import { Component } from '@angular/core';
import { MyParentClass, MyChildClass } from '../../providers/my-provider'
@Component({
selector: 'page-home',
templateUrl: 'home.html',
providers: [
MyParentClass,
MyChildClass
]
});
export class homePage {
constructor(private parentClass: MyParentClass, private childClass: MyChildClass) {
}
}