Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set path alias in angular 4 application

Tags:

angular

Is there any way to set path aliases in Angular with TypeScript since putting path like

import { AuthService } from '../../../common/AuthService';
import { ContactService } from '../../../common/ContactService';

It is very confusing i.e. to remember the relative path URI. Is there any way to create path aliases and use them throughout the application, like browserify?

like image 970
Mantu Nigam Avatar asked May 27 '17 13:05

Mantu Nigam


Video Answer


1 Answers

If you use typescript, the best way to deal with this problem is to put paths configuration in project's tsconfig.json:

"baseUrl": "src",
"paths": {
  "@app/*": ["app/*"],
  "@env/*": ["environments/*"]
}

Please, refer 2nd point in the following article https://medium.com/@tomastrajan/6-best-practices-pro-tips-for-angular-cli-better-developer-experience-7b328bc9db81, or official ts docs https://www.typescriptlang.org/docs/handbook/module-resolution.html#base-url

like image 71
Alex Dzeiko Avatar answered Sep 28 '22 10:09

Alex Dzeiko