2017-10-30 12 views
0

絶対パス(つまり別のモジュール)を使用してコンポーネントテンプレート/スタイルを読み込む方法は?絶対パスを使用したテンプレート/スタイルのロード

@Component({ 
    selector: 'a-component', 
    templateUrl: 'shared-module/components/another-shared-component/component.html', 
    styleUrls: ['shared-module/components/another-shared-component/component.scss'] 
}) 

は私が/~/を使用してトライを持っているだけで、モジュール名で始まるが、どれも働きました。

答えて

0

相対パス演算子./../を試しましたか? component.htmlはそれ以上の二つのレベル(フォルダ)であった場合は、次のようになります。

templateUrl: '../../shared-module/components/another-shared-component/component.html'

カレントディレクトリが異なるサブフォルダにいる場合:

templateUrl: './shared-module/components/another-shared-component/component.html'

+0

'../'動作しますが、それは意志ますコンポーネントフォルダに到達するには長い道のりでなければならないので、私は絶対的なアプローチを探していたのです。 – Ayman

+0

多分[このように質問](https://stackoverflow.com/questions/34925992/how-to-avoid-imports-with-very-long-relative-paths-in-angular-2)は役に立ちます – Milo

+0

これはのためですTypeScriptモジュールシステム。 Angularはこれを考慮していないようです(ただし、そうしても意味があります)。 – Ayman

関連する問題