2016-11-04 8 views
1

npmモジュールでよく使用されるコンポーネントを記述していますが、templateUrlを参照する最も良い方法は何か分かりませんが、動作していますがnode_modulestemplateUrlでは、となります。これは、node_module direcotryの名前を変更できるためです。npmパッケージのAngular2コンポーネントtemplateUrl

他の作業方法がありますか?例えば

:私はモジュールをロードするためにsystemjsを使用"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; 

    ... 
} 

答えて

1

テンプレートはSystemJS経由でロードされないため、マッピングは使用できません。

../BootstrapAlert/BootstrapAlert.htmlのような相対パスを使用でき、 gulpのような特定のビルドツールのテンプレートインライナがあることに注意してください。

+1

コンポーネントを公開する予定の場合は、テンプレートを埋め込むことをお勧めします。 Webpack/Angular-Cliのユーザーは、私が公開したモジュールにはテンプレートへの相対パスがある問題がありました。 – JayChase

関連する問題