Angular 2 stable - @NgModule design
See original GitHub issueThe 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:
- Created 7 years ago
- Reactions:9
- Comments:7 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
👍 That’s a great idea. Maybe it could be a flag similar to ng1 strict dependency injection.