Confused about @NgModule introduced in Angular 2

I am trying to reproduce Angular2, and when I upgraded the base codes to Angular 2.0.0-RC5, I found changes made, @NgModule, which is equivalent to angular. moudle () in Angularjs 1.x?

For me, @ngModule makes things complicated.

When I used Angular 1.x, there are posts about angular.module in the communities, because there are some javascript module systems.

By default, the generated Angular-cli codes are based on SystemJS, we can use Typescirpt to organize the structure of the source codes.

Why do we need @NgModule, is this a logical representation of the organization of the application at runtime?

I assume that @NgModule is for a module-based architecture for Angular2, and @ngModule can be reused in different applications. Compare with other module / bundle / plugin based platforms I've used in recent years. It lacks some features.

  • @NgModule provides import / export functions, but how to import modules without the Typescript import clause and refuse others @NgModule to import @NgModule private components / pipes / services.
  • There is no route prefix for @NgModule, imagine that t``he @NgModule is supported by the 3party command. eg. general comment module for any email application, how to avoid route conflict, how to redefine route definitions, how to configure @ngModule in @NgModule host?
  • RouteModule.forRoot() ( forChild), @NgModule, .

    @NgModule(route:{prefix:'/comment', config: commentRouteConfigs}) export class CommentModule{}

    API-, API- @NgModule,

  • , @NgModule, -.

  • @ngModule (mout/unmout load/unload .., desc Angular) // @ngModule ?
  • @NgModule @ngModule , @ngModule .

.

+4
1

, NgModule .

+2

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


All Articles