简体   繁体   中英

Typescript import class to service class

here is my folder structure and i want to import PolicyDetail class to Policy.Service class how can i do that here im tired following code

in my Policy.Service class :

import { PolicyDetail } from '/App/Shared/PolicyDetail';

folder structure

App
 -- Shared/
         -  PolicyDetail.ts

 --Quote/
        -Services /
                  -- Policy.Service.ts

Imports are always relative to the current file's location. That means you have to specify how to get to PolicyDetail from Policy.Service. It would be something like this.

import { PolicyDetail } from '../../Shared/PolicyDetail';

Demistification:

  1. We start from the location of Policy.Service that being the Service folder.

  2. We go to the parent (../) and end up in the Quote folder.

  3. From here we go once again to the parent (../) and end up in the App folder.
  4. From here we have to go in to the shared folder (Shared/) and specify which file we want from it (PolicyDetail).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM