简体   繁体   中英

Using realative paths in Angular: Cannot find module

Helloo, I am trying to import a class from a different component in Angular. 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:

  • src
    • /app
      • /_services
      • /chat-app
        • /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

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