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'
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).
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.
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.
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.
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";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With