基本上,在Angular 6
中,您可以从顶部或底部开始import
。
我的两个选项
它们可以使用由angular CLI
生成的默认配置。
从顶部
如果它离应用程序的根更近,我更喜欢这种方式
import { DateService } from "src/app/shared-services/context/date.service";
从底部
import { DateService } from "../../../../../../../shared-services/context/date.service";
上下文:
TypeScript配置:tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
Angular的技术栈
ng -v
Angular CLI: 6.0.8
Node: 8.9.0
OS: win32 x64
Angular: 6.0.7
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.8
@angular-devkit/build-angular 0.6.8
@angular-devkit/build-optimizer 0.6.8
@angular-devkit/core 0.6.8
@angular-devkit/schematics 0.6.8
@angular/cli 6.0.8
@ngtools/webpack 6.0.8
@schematics/angular 0.6.8
@schematics/update 0.6.8
rxjs 6.2.1
typescript 2.7.2
webpack 4.8.3
"baseUrl"
maybe should set"./src"
andpaths relate to it
wiil get it to work, it origin to be"./"
, but my is not work, I don't know why! and then add"paths": { "@app/*": ["app/*"] }
totsconfig.json
and use likeimport { PageNotFoundComponent } from '@app/error-page/page-not-found.component';
- Cheney