3

Is there any way to use namespace for custom paths in Angular 5? Currently I use

import { AuthService } from './../../modules/auth/auth.service';

What I am trying to achieve is using @module or custom @name for a particular path. The code should look like below and be usable in every folder level

import { AuthService } from '@modules/auth/auth.service';
ninja dev
  • 1,687
  • 2
  • 12
  • 12
  • Possible duplicate of [ES6 import using at ('@') sign in path in a vue.js project using Webpack](https://stackoverflow.com/questions/42749973/es6-import-using-at-sign-in-path-in-a-vue-js-project-using-webpack) – Estus Flask Feb 16 '18 at 08:44

1 Answers1

5

Yes, there is paths property in tsconfig.json configuration:

{
   ...
   "compilerOptions": {
       ...
       "paths": {
           "@core/*": ["app/core/*"],
           "@shared/*": ["app/shared/*"]
    }      
}
Zlatko
  • 18,936
  • 14
  • 70
  • 123
  • This did the trick , all is working but my Vs-code IDE shows error on line.. know any workaround for this? – ninja dev Feb 16 '18 at 10:05
  • Not sure, my IDE reads these paths and knows how to handle it.There is a bug open: https://github.com/angular/angular-cli/issues/8138 Maybe search a bit more to find out if other people have this problem? – Zlatko Feb 16 '18 at 13:38
  • 1
    Fixed it.. i was using '@module' for importing all exported members instead i used '@module/index' – ninja dev Feb 19 '18 at 04:29