Reputation: 5537
I am looking for a way to manage import paths in angular 2.0. I would perfer to configure it once then call it like a variable. e.g.
import { ProductService } from Paths.Product.ProductService;
this allows me to move the folder location of the class and make one other change in the application.
Is something like this available.
Thanks
Upvotes: 0
Views: 60
Reputation: 71901
You can use the paths
property in your tsconfig.json
:
{
"compilerOptions": {
...
"baseUrl": ".",
"paths": {
"@Product/*": ["./path/to/product/*"]
},
"rootDir": "."
}
}
you can then import any file inside your /path/to/product
folder like:
import { ProductService } from '@Product/service';
and if you want to change your path, you only have to edit it in the tsconfig
Upvotes: 2