我创建了一个包含应用程序和库的角度工作空间,为解释在这里。该库包含一个以public-api.ts
.
问题是我无法在应用程序中导入库服务。我得到
找不到模块:错误:无法解析“component-that-uses-the-service.ts”中的“lib-name/services/utils.service”
在lib-name
工作区中创建的库在哪里。
应用程序不会在 Visual Studio Code 中引发任何错误,并且库模块会导入到使用它的组件中。
当我运行应用程序时,ng serve
我收到错误消息。
根据 Angular 团队的说法:
When you build your own library, it has to find the mapping in your tsconfig paths.
tsconfig 路径似乎没问题,它们是在我创建库时配置的ng generate library
(tsconfig 文件位于工作区的根目录中)。
我错过了什么?
您不需要使用完整路径导入您的服务。
你必须像这样导入你的服务
import { YourService } from 'lib-name'
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句