Use modules in angular?

I am learning angular4 . I read somewhere that some version of angular2 introduced modules using @NgModule.

Suppose I create an accounting application. Thus, there will be different functions, such as groups, registers, etc. Thus, based on the functionality, I can divide it into modules, such as GroupsModule, LedgersModule, etc. Therefore, first create your own GroupsModule, which will look like this:

GroupsModule
  |--Classes
       |--Group.ts
  |--Components
       |--Group-list
            |--Group-list.component.ts
            |--Group-list.component.html
            |--Group-list.component.css
       |--Group-create
            |--Group-create.component.ts
            |--Group-create.component.html
            |--Group-create.component.css
  |--Services
       |--Group.service.ts
  |--Group.Module.ts

Now, if I create the Ledger module, I will have to reorganize the GroupsModule and transfer some of its files to the SharedModule, because my LedgersModule will have to access some parts of the GroupModule, so now my GroupModule will look like this:

GroupsModule
  |--Components
       |--Group-list
            |--Group-list.component.ts
            |--Group-list.component.html
            |--Group-list.component.css
       |--Group-create
            |--Group-create.component.ts
            |--Group-create.component.html
            |--Group-create.component.css
  |--Group.Module.ts

LedgersModule will look like this:

LedgersModule
  |--Classes
       |--Ledger.ts
  |--Components
       |--Ledger-list
            |--Ledger-list.component.ts
            |--Ledger-list.component.html
            |--Ledger-list.component.css
       |--Group-create
            |--Ledger-create.component.ts
            |--Ledger-create.component.html
            |--Ledger-create.component.css
  |--Services
       |--Ledger.service.ts
  |--Ledger.Module.ts

SharedModule :

SharedModule
  |--Classes
       |--Group.ts
  |--Services
       |--Group.service.ts
  |--Shared.Module.ts

:

1:

, .

: 2

, .

, SomeOtherModule, LedgersModule. , LedgersModule SharedModule. SomeOtherModule SharedModule, Ledger, . SomeOtherModule Group.service.ts, SharedModule. , . , SomeOtherModule () GroupModule SharedModule.

. , .

? .

? AppModule ?

+4

Source: https://habr.com/ru/post/1675032/


All Articles