2016-11-04 55 views
1

我正在npm模块中编写一个常用组件,我不知道什么是templateUrl的最佳方式,它正在工作,但是我不想包含node_modulestemplateUrl,,因为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