Basically, in Angular 6 you can start the import from the top or bottom.
My two options
They are available with default config generated by angular CLI
From the top
I prefer this way if it's closer from the root of the app
import { DateService } from "src/app/shared-services/context/date.service";
From the bottom
import { DateService } from "../../../../../../../shared-services/context/date.service";
Context:
TypeScript config: 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's stack
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 itwiil 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.jsonand use likeimport { PageNotFoundComponent } from '@app/error-page/page-not-found.component';