简体   繁体   English

Angular找不到模块本地文件

[英]Angular can't find module local file

In my application, in various component I called SharedService 在我的应用程序的各个组件中,我称为SharedService

but ts error can't find module Sharedservice when 但ts错误找不到模块Sharedservice时

import { SharedService } from 'src/app/shared/shared.service';

even Path Intellisense is pointing properly 即使Path Intellisense指向正确

But, when I changed to relative 但是,当我改变为相对

import { SharedService } from '../app/shared/shared.service';

Is there any place where it is need to be written to point to src/... 有什么地方需要写它指向src / ...

I think you need to configure your tsconfig.json as follows, 我认为您需要按以下方式配置tsconfig.json,

  "compilerOptions": {
    "baseUrl": "./src",
    "paths": {
      "components/*":  [ "app/components/*" ],
      "services/*":  [ "app/services/*" ],
      "shared/*":  [ "app/shared/*" ]
    },

You can do import as follows 您可以执行以下导入

import { SharedService } from 'shared/shared.service';

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

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