Javascript 如何在Ionic2提供程序上创建和使用模块类?
我想用模块扩展我的提供程序以使用,比如Javascript 如何在Ionic2提供程序上创建和使用模块类?,javascript,angular,typescript,ionic2,ionic2-providers,Javascript,Angular,Typescript,Ionic2,Ionic2 Providers,我想用模块扩展我的提供程序以使用,比如classA.moduleClassB,但我不能也不知道如何将模块类对象作为提供程序导入我的控制器页面 示例(如我所愿): providers/my provider/my provider.ts export class MyParentClass { //... } export module a { class MyChildClass { //... } } import { Component } from
classA.moduleClassB
,但我不能也不知道如何将模块类对象作为提供程序导入我的控制器页面
示例(如我所愿):
providers/my provider/my provider.ts
export class MyParentClass {
//...
}
export module a {
class MyChildClass {
//...
}
}
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) {
}
}
import {Injectable} from "@angular/core";
@Injectable()
export class MyParentClass {
//...
}
export module a {
@Injectable()
export class MyChildClass {
//...
}
}
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) {
}
}
页面/home/home.ts
export class MyParentClass {
//...
}
export module a {
class MyChildClass {
//...
}
}
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) {
}
}
import {Injectable} from "@angular/core";
@Injectable()
export class MyParentClass {
//...
}
export module a {
@Injectable()
export class MyChildClass {
//...
}
}
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) {
}
}
只能注入标记为可注入的类。将classB标记为可注入,然后像您所做的那样将其注入构造函数中 为了使用正确的依赖项注入,请将访问修饰符更改为private。然后可以在classA中访问classB 宠儿 我想用模块扩展我的提供程序,以便像classA.moduleClassB一样使用,但我不能,也不知道如何将模块类对象作为提供程序导入控制器页面 应该是这样的: providers/my provider/my provider.ts
export class MyParentClass {
//...
}
export module a {
class MyChildClass {
//...
}
}
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) {
}
}
import {Injectable} from "@angular/core";
@Injectable()
export class MyParentClass {
//...
}
export module a {
@Injectable()
export class MyChildClass {
//...
}
}
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) {
}
}
页面/home/home.ts
export class MyParentClass {
//...
}
export module a {
class MyChildClass {
//...
}
}
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) {
}
}
import {Injectable} from "@angular/core";
@Injectable()
export class MyParentClass {
//...
}
export module a {
@Injectable()
export class MyChildClass {
//...
}
}
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) {
}
}
你能编辑你的答案并写一个简单的例子吗。谢谢用一个例子编辑了我的帖子:)太感谢了!投票!