Reputation: 968
I know in my service and component I need to use import {MyService} from '../my-service' if I want to import a service.
But my question is:
Is there a quick way to specify the path where my service is? Sometimes I use '../'
, sometimes I use './'
. Sometimes I have to use '../parentFolderOfMyService'
, sometimes I have to use '../parentFolderOfMyService/my-service'
.
P.S. I am using visual studio 2017.
Upvotes: 0
Views: 451
Reputation: 2044
It's not about Service or component , all about folder/files hierarchy.
when we will use ../../something1/something2/service
is when our would be like this.
importing service.ts in our service.component.ts
app
|something1
|something2
-(service.ts)
-(service.html)
-service.component.ts
for more
src
|app
|folder1
(.ts file)
|folder2
(.ts file1)
(.ts file2)
|app.module.ts
If I'm importing folder1 .ts file in folder2 .ts file
import {filecomponent} from 'app/folder1/file.component'
Importing folder2 file1.ts file in folder2 file2.ts file
import {file1component} from './file1.component'
Importing folder1 .ts file in app.module.ts
import {filecomponent} from './folder1/file.component'
Upvotes: 0