angle2プロジェクトでは、すべてのモデルのtsファイルを特定のフォルダ/ app/common/model/*に配置します。 親戚のパスで私のコンポーネントでそれらを呼び出すことはできますが、非常に面倒です。 2つのソリューションは、カスタムパスがベストです:StackOverflow: Relative Paths for SystemJS & ES module imports。 しかし、私のIDEはパスを見つけることができません。ここに私のTSconfigは次のとおりです。Angular2インポート絶対パスまたはカスタムパス(typescript 2)
私のコンポーネントで{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "built",
"baseUrl": ".",
"paths": {
"mymodel/*": [
"app/common/model/*"
]
}
}
}
: import { Address } from 'mymodel/address.model';
IDE:[TS]モジュールを見つけることができません.... 私はパス
第二の溶液中でまたは*なしで試してみました: Stackoverflow: Angular 2, imports between different folders
IDEとコンパイルは、コンポーネント内のフルパスで、OKです: import { Address } from 'common/model/address.model';
とのTSconfig:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": true,
"outDir": "built",
"baseUrl": ".",
"paths": {
"*": [
"app/*",
"node_modules/*"
]
}
}
}
しかし、我々はすべてのモデルのページの負荷に404を持っています。 おそらくsystemjsファイルの設定ですか?
どちらの場合でも、私は "outdir"パラメータが問題であり、何かが欠けていると思います。
多くのご協力ありがとうございます!
よろしく、
活字体:2.0.6 角度:2.0.0
どのIDEを使用していますか?私の場合(IntelliJ/Webstorm)、インポートはほとんど入力しません。IDEがそれを私のために追加します。 –
Visual Studioコード。あなたの中では絶対パスですか? – lginlap
最初の解決策は他のIDEとうまくいっています...申し訳ありませんが、それは偽の問題です – lginlap