2017-03-08 1 views
0

나는 classA.moduleClassB처럼 사용하는 모듈 내 제공을 확장 싶지만 그럴 수 없어 나는 (내가 원하는) 공급자Ionic2 제공자에서 모듈 클래스를 만들고 사용할 수 있습니까?

예로 내 컨트롤러 페이지에 모듈 클래스 객체를 가져올 방법을 모른다 :

제공/내-제공/내 - provider.ts

export class MyParentClass { 
    //... 
} 
export module a { 
    class MyChildClass { 
     //... 
    } 
} 

페이지/홈/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) { 
    } 

} 

답변

1

주사 가능한 것으로 표시된 클래스 만 주입 할 수 있습니다. 귀하의 클래스 B를 주사제로 표시하고 그랬던 것처럼 생성자에 주입하십시오.

적절한 종속성 삽입을 사용하려면 액세스 한정자를 개인으로 변경하십시오. 그런 다음 classA에서 클래스 B에 액세스 할 수 있습니다.

좋아하는 내가 classA.moduleClassB처럼 사용하는 모듈 내 제공을 확장하고자하지만 난 할 수 없습니다 나는 공급자로 내 컨트롤러 페이지에 모듈 클래스 객체를 가져올 방법을 모르는

처럼 보일 것이다 이 :

제공/내-제공/내 - provider.ts

import {Injectable} from "@angular/core"; 

@Injectable() 
export class MyParentClass { 
    //... 
} 
export module a { 
    @Injectable() 
    export class MyChildClass { 
     //... 
    } 
} 

페이지/홈/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) { 
    } 

} 
+0

답장을 편집하고 간단한 예를 쓸 수 있습니까? 감사! –

+0

예를 들어 내 게시물을 편집했습니다. –

+0

너무 많이 감사드립니다! 투표하기! –

관련 문제