0

With the following command I generated a library named (cac-common)

ng generate library cac-common

In this library I have 2 modules:

cac-common-utility (ng generate module cac-common-utility  --project=cac-common)

cac-common-security (ng generate module cac-common-security  --project=cac-common)

When I want to use the cac-common-security module I have to import it in any module as below:

import { CacCommonSecurityModule } from 'cac-common';

...
imports:[ CacCommonSecurityModule ]
...

My question are:

1- the import above load the whole cac-common library or load only cac-common-security module ?

2- why I can not import the cac-common-security module like the following ?

import { CacCommonSecurityModule } from 'cac-common/lib/cac-common-security/cac-common-security.module';
2
  • Can you update your 2 follow up questions? I am a bit confused on what you are asking. As well as for those can you supply a brief example? Thanks Commented Jan 8, 2020 at 21:32
  • When you get a chance to make those updates I will take another look. Thanks Commented Jan 9, 2020 at 14:09

1 Answer 1

1

You Can use Library by Importing its modules.

Or importing a name that wrap and export all the modules in it.

If you import modules via relative path of its directory, the source of library always must be available. if you import by exported name, you can easily install it everywhere you want.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks , your answer is related to my second question . What is the answer of my first question ?
Import Module from package or library just import the module with dependency that set inside the module not anything more
if that is the case , why in the earlier version of Angular Material if we wanted to use button we imported button like : import {MatButtonModule} from @angular/material but in the current version we can import like : import {MatButtonModule} from '@angular/material/button , It means there is a diffrence between them . based on your answer , there is no diffrence between @angular/material/button and @angular/material
for example if you want to use ngx-button : valor-software.com/ngx-bootstrap/#/buttons you have two options to import 1- import { ButtonsModule } from 'ngx-bootstrap/buttons' 2- import { ButtonsModule } from 'ngx-bootstrap'; they recommended to use 1 . based on your answer , there is no difference between , so why they recommended import 1
There is a big Different between import form modules seperately and import from barrels (group of exports) see this post stackoverflow.com/q/54257329/2126355

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.