in angular I need to import files , class from another files to my file, class.. I am confused with dots and slashes, cant find any logic sometimes. Would you please help?
Asked
Active
Viewed 167 times
0
-
File paths are relative to the baseUrl in your compiler options. See this question for more about import paths: https://stackoverflow.com/questions/34614818/angular2-root-relative-imports – mfluehr Aug 19 '22 at 16:19
-
Is there any automat way to add it the the top of the file? – Nana Aug 19 '22 at 17:13
-
Yes, depending on the IDE you use. VS Code, for example: https://code.visualstudio.com/docs/languages/javascript#_auto-imports – mfluehr Aug 19 '22 at 17:31
1 Answers
0
./
./ means moving back from current file.
Example
In above image I'm at test.component.ts, by using ./ I came out from that file and currently I'm at test folder.
../
../ means moving back from current folder.
Example
by doing ./ I came out from the test.component.ts file after that i used ../ that means I came out from test folder. so ./../ help me to get out of test folder.
/
/ means we are moving forward
Example
After ./../ I will be at src scope and I can directly move forward into app folder by adding / final path will be ./../app/
Conclusion=>
/ (normal slash) - moving forward
./ (slash with pre dot) - moving back from file
../ (slash with 2 pre dots - moving back from folder

Exception
- 571
- 1
- 3
- 15