Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Absolute path in Angular cli project

How can I use absolute path in an angular cli generated project?

So I have this path : src -> app -> shared and I would like to write import {} from 'shared/ffdsdf/my.module.ts' instead of '../shared/ffdsdf/my.module.ts'

like image 411
user3409988 Avatar asked Dec 23 '16 19:12

user3409988


People also ask

How do you specify an absolute path?

An absolute path is defined as specifying the location of a file or directory from the root directory(/). In other words,we can say that an absolute path is a complete path from start of actual file system from / directory. Relative path is defined as the path related to the present working directly(pwd).

What is relative and absolute path in angular?

It is recommended to use the Relative path. Using absolute path breaks our code if the parent URL structure changes. The relative path will not change even if the parent path changes. To go to the parent route.

What is the use of absolute path?

An absolute path refers to the complete details needed to locate a file or folder, starting from the root element and ending with the other subdirectories. Absolute paths are used in websites and operating systems for locating files and folders. An absolute path is also known as an absolute pathname or full path.

How do I know if my path is absolute?

You can determine the absolute path of any file in Windows by right-clicking a file and then clicking Properties. In the file properties first look at the "Location:" which is the path to the file.


1 Answers

better sample:

tsconfig.json

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

use:

import { someService } from "@app/core/some.service";

instead of:

import { someService } from "./../../core/some.service";
like image 114
Masoud Bimmer Avatar answered Oct 12 '22 17:10

Masoud Bimmer