I am new to angular,
started writing my first library, containing components, services, directives.
i listed my components, services, directives in the library's exports
array, but still:
When using the library form another library or application, and to compile successfully,
i needed to list my components and services in the public-api.ts
. why ? isn't the ngModule's exports
array enough?
now deleted the components,services, directives from the exports
array and everything still works. why ?
reading around the docs at angular.io, it looks like public-api.ts
and exports
serve the same purpose - i am probably missing something basic here.
The exports
of a @NgModule
defines what is exposed to other modules when that module is imported in the imports
of another module. The public-api
acts as a barrel file for cleaner path imports.
// Instead of this
import { ExampleService } from '@lib/services/example.service';
import { AntoherService } from '@lib/sevivces/another.service';
// You can do this
import { ExmpaleService, AnotherService } from '@lib';
https://angular.io/api/core/NgModule#exports https://basarat.gitbooks.io/typescript/docs/tips/barrel.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With