question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular 2 stable - @NgModule design

See original GitHub issue

The big change in RC5 was the move to modules. It moves away from declaring directives and services in components to declaring them in “module files”. This actually lines up well with the angular.module function of ng1. Here my initial idea of how this could be mapped. Any thoughts?

@NgModule({
  declarations: [ AwesomePipe, HighlightDirective, TitleComponent ], // components, directives, filters
  providers: [ UserService ], // provided services
  imports: [ SharedModule, 'ngAnimate' ], // module dependencies
  exports: [ HighlightDirective, UserService, SharedModule ] // shows what is intended to be public
})
  • declarations - registers components directives and pipe classes with angular.module(...).directive() or .filter()
  • providers - registers services via angular.module(...).service()
  • imports - modules to register in angular.module(..., [dependencies]) (could be decorated module or string)
  • exports - show what declarations are intended to be used in other modules (even though ng1 makes all declarations public)
  • bootstrap - root component to place in dom
  • entryComponents - not needed?

References:

https://angularjs.blogspot.com/2016/08/angular-2-rc5-ngmodules-lazy-loading.html https://angular.io/docs/ts/latest/guide/ngmodule.html https://angular.io/docs/ts/latest/cookbook/rc4-to-rc5.html https://docs.angularjs.org/api/ng/function/angular.module https://docs.angularjs.org/api/ng/type/angular.Module

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:9
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
Hotellcommented, Sep 17, 2016

@aciccarello @JamesHenry I would include whole API, and explicitly state in source code docs and Markdown docs, that they don’t do anything as for now ( maybe later we can provide some mechanism to emit warnings or errors when someone uses something from some feature module and didn’t exported that component/directive/pipe etc… )

It will enforce the right Angular 2 architecture mindset. Leaving comments is not very good idea IMHO.

3reactions
aciccarellocommented, Sep 17, 2016

maybe later we can provide some mechanism to emit warnings or errors when someone uses something from some feature module and didn’t exported that component/directive/pipe etc…

👍 That’s a great idea. Maybe it could be a flag similar to ng1 strict dependency injection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

NgModules - Angular
NgModules configure the injector and the compiler and help organize related things together. An NgModule is a class marked by the @NgModule decorator....
Read more >
Introduction to Angular concepts
NgModules collect related code into functional sets; an Angular ... helps in managing development of complex applications, and in designing for reusability.
Read more >
Introduction to modules - Angular
Angular applications are modular and Angular has its own modularity system called NgModules. NgModules are containers for a cohesive block of code dedicated ......
Read more >
Angular coding style guide
Looking for an opinionated guide to Angular syntax, conventions, and application structure? Step right in. This style guide presents preferred conventions ...
Read more >
Feature modules - Angular
Feature modules are NgModules for the purpose of organizing code. ... The structure of an NgModule is the same whether it is a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found