0

I've created one angular library project that has one component and once api (UserApi) (abstract class). I've another project which consume this library. This project also has a service (UserService implements UserApi) that implements the api of the library.

In my project module file, I've added the provider using following code.

{ provide: UserApi, useExisting: UserService }

Now, there are two ways I can have an import statement for UserApi.

import { UserApi } from 'mylibrary'; or import { UserApi } from 'projects/mylibrary/src/public_api';

First one is the proper way. However, It is not working when I use the first import. It works when I use the second import. But I cannot release my code with second line. Upon further checking, I found that as I am accessing the UserApi from the released library, it is accessed through the definition file.

and the code is like

import { Observable } from 'rxjs/Observable'; export declare abstract class UserApi { abstract getConfigName(): Observable<string>; }

In my original code, I don't have 'declare' keyword while the released code has it. And that is the reason my project isn't able to use the provided service.

How can this be fixed ?

Update: Code from public_api

`

 export * from './lib/user-shared.service';
 export * from './lib/user-shared.component';
 export * from './lib/user-shared.module';
 export * from './lib/component/usermanager.component';
 export * from './lib/coreapi/userapi';

`

Himal Patel
  • 387
  • 4
  • 19
  • Can you paste the code from your public_api.ts? – profanis Feb 05 '19 at 13:36
  • updated the post and included the code from public_api.ts – Himal Patel Feb 05 '19 at 14:01
  • Try explicit export. `export { UserApi } from './lib/coreapi/userapi'; ` Aside from that, how do you import the library in your project? Do you use any repo like npm, nexus, artifactory or so? – profanis Feb 07 '19 at 17:04
  • Hi @profanis, got the issue. One of the import was importing directly from the library file location and not using the exported library. That was causing the issue. Thanks for your help! – Himal Patel Feb 08 '19 at 09:32

0 Answers0