An open API service indexing awesome lists of open source software.

https://github.com/danwild/angular2-heroes

Angular2 BETA tutorial and notes
https://github.com/danwild/angular2-heroes

Last synced: 26 days ago
JSON representation

Angular2 BETA tutorial and notes

Awesome Lists containing this project

README

          

# Notes/Takeaways



  • Naming conventions: filename is the name of the module (lower-case-dashed), and the module type is denoted in a postfix, e.g.


    • Class component postfixed with .component,
      e.g. app.component (.ts) should export AppComponent.


    • Services postfixed with .service
      e.g. hero.service (.ts) should export HeroService.




  • @Component used to define metadata for an Angular component

  • CLASSES when we need logic and behavior

  • INTERFACES when we just want type checking (also lighter weight, as nothing needs to be transpiled for interface)

  • Can use backticks ` for multi-line template strings

  • Component styles scoped to that specific component only (+1 for modularity)


  • @Injectable() decorator used to enable DI for a service etc., best practice to add it from the start (consistency, future-proofing)

  • To get an injectable service, we must add it to providers array in @Component metadata.

    Note: components inherit the services of the other component above them in the component tree, so you need to think about where
    in the tree you define a service provider (only one per instance of app).


  • Injectable go into constructor

  • Private vars (e.g. an injected service) should be prefixed with _ underscore to warn that it's not part of components public API

  • To avoid heavy lifting in constructor (web service/config loading), we have Angular's ngOnInit Lifecycle Hook