简体   繁体   English

引用库 angular 创建的服务时出错

[英]Error when referencing service created by library angular

I have created an angular library and I am referencing this library in a separate external project.我已经创建了一个 angular 库,我在一个单独的外部项目中引用了这个库。 However, whenever I am referencing a service I get the below error:但是,每当我引用服务时,我都会收到以下错误:

Module not found: Error: Package path ./lib/services/test.service is not exported from package D:\Projects\Admin\node_modules\my-lib (see exports field in D:\Projects\Admin\node_modules\my-lib\package.json)

Service:服务:

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class TestService {

  constructor() { }

  getTest(): string{
    console.log('inside the service');
    return "This is inside the service";
  }
}

my-lib.module:我的 lib.module:

import { NgModule } from '@angular/core';
import { myLibComponent } from './my-lib.component';


@NgModule({
  declarations: [
    myLibComponent
  ],
  imports: [
  ],
  exports: [
    myLibComponent
  ]
})
export class myLibModule { }

You have to export the service from library.您必须从库中导出服务。 In project.ts of library you have to insert:在库的 project.ts 中,您必须插入:

export * from 'your path';从“你的路径”导出 *;

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

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