简体   繁体   English

打字稿导入类到服务类

[英]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 这是我的文件夹结构,我想将PolicyDetail类导入到Policy.Service类中,我该如何执行以下代码

in my Policy.Service class : 在我的Policy.Service类中:

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. 这意味着您必须指定如何从Policy.Service转到PolicyDetail。 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. 我们从Policy.Service的位置开始,即Service文件夹。

  2. We go to the parent (../) and end up in the Quote folder. 我们转到父级(../),最后进入Quote文件夹。

  3. From here we go once again to the parent (../) and end up in the App folder. 从这里我们再次转到父(../),最后进入App文件夹。
  4. From here we have to go in to the shared folder (Shared/) and specify which file we want from it (PolicyDetail). 从这里,我们必须进入共享文件夹(Shared /)并指定要从中共享的文件(PolicyDetail)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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