• Members 3 posts
    Aug. 7, 2018, 3:24 p.m.

    Solution :
    Instead of using a relative path to your service:

    import { someservice } from ‘../../../services/some.service’;

    You can instead user an alias that points to your services:

    import { someservice } from ‘@myservices’;

    Steps :
    To achieve this, first, you need to create a TypeScript files for exporting all your services – let’s call it services.ts. Then export all the services we want from inside this file:

    export * from ‘./some.service’;
    export * from ‘./some.other.service’;

    After that, modify the typescript configuration (tsconfig.json) and add a reference to our service.ts under our paths:

      "compileOnSave": false,
      "compilerOptions": {
        "baseUrl": "./",
        "paths": {
          "@services": ["src/app/services/services "],

    This way, any changes to the path of a service (like moving it somewhere else or just renaming it), then all you need to do is reflect the new location inside the service.ts file.

    For any doubts, please feel free to comment! :)