简体   繁体   English

在 Angular 中使用实际路径:找不到模块

[英]Using realative paths in Angular: Cannot find module

Helloo, I am trying to import a class from a different component in Angular.您好,我正在尝试从 Angular 中的不同组件导入 class。 But I keep getting error the Error:但我不断收到错误错误:

Cannot find module './app/_services/modal.service' or its corresponding type declarations.

My import statement looks like this我的导入语句看起来像这样

 import {ModalService} from './app/_services/modal.service';

My directory tree looks like this, I am trying to go from the chatcomponent to _services:我的目录树看起来像这样,我正在尝试将 go 从聊天组件到 _services:

  • src源代码
    • /app /应用程序
      • /_services /_服务
      • /chat-app /聊天应用
        • /chat/chatcomponent.ts /chat/chatcomponent.ts

You should start the import path from src folder src/app/_services/modal.service or you should move back two folders so to reach _services folder ../../_services/modal.service您应该从 src 文件夹src/app/_services/modal.service开始导入路径,或者您应该向后移动两个文件夹以到达 _services 文件夹../../_services/modal.service

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

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