2016-11-04 8 views
1

npm 모듈에서 일반적으로 사용되는 구성 요소를 작성하고 있는데 templateUrl을 참조하는 가장 좋은 방법은 무엇인지 모르겠지만 작동하지만 node_modules을 포함하고 싶지 않습니다. templateUrl,에서 node_module direcotry의 이름을 바꿀 수 있기 때문입니다.npm 패키지의 Angular2 구성 요소 templateUrl

다른 사용 방법이 있습니까? 예를 들어

: "npm:my-commons-ts/my-commons/components/BootstrapAlert/BootstrapAlert.html"

@Component({ 
    selector: "bs-alert", 
    templateUrl: "node_modules/my-commons-ts/my-commons/components/BootstrapAlert/BootstrapAlert.html", 
}) 
export class BootstrapAlertComponent { 

    public errors: DisplayMessage[] = []; 
    public successes: DisplayMessage[] = []; 
    public warnings: DisplayMessage[] = []; 
    public infos: DisplayMessage[] = []; 

    @Input() 
    public bcn: string = null; 

    ... 
} 

나는 모듈을로드 할 수 systemjs를 사용합니다.

답변

1

템플릿은 SystemJS를 통해로드되지 않으므로 매핑을 사용할 수 없습니다.

상대 경로 (예 : ../BootstrapAlert/BootstrapAlert.html)를 사용할 수 있으며 (gulp)과 같은 특정 빌드 도구의 템플릿 인라이저가 있습니다.

+1

구성 요소를 퍼블리시 할 계획이라면 템플릿을 사용하는 것이 좋습니다. Webpack/Angular-cli 사용자는 내가 게시 한 모듈에 템플릿에 대한 상대 경로가있는 문제가있었습니다. – JayChase

관련 문제