Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert relative import to absolute in angular 6?

How to convert relative import to absolute import in angular 6?

For example

make environments/environment instead of

 ../../../../environments/environment
like image 497
Max K Avatar asked Apr 12 '18 16:04

Max K


1 Answers

This is actually for TypeScript, not necessarily Angular. Here is an example of what you need to add to your tsconfig.json file in the root of your project:

{
  // Other TS options here
  "compilerOptions": {
    // more stuff is usually here
    "paths": {
      "@constants/*": ["./app/constants/*"],
      "@components/*": ["./app/components/*"],
      "@directives/*": ["./app/directives/*"],
      "@env/*": ["./environments/*"],
      "@models/*": ["./app/models/*"],
      "@services/*": ["./app/services/*"],
      "@states/*": ["./app/state-management/*"]
    }
  },
  // ...other stuff can be here too
}

Then, you will be able to do this within your specific files/components:

import { LoggerService } from '@services/logger/logger.service';
like image 83
th3n3wguy Avatar answered Oct 13 '22 03:10

th3n3wguy