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
- Host: GitHub
- URL: https://github.com/danwild/angular2-heroes
- Owner: danwild
- Created: 2016-01-14T23:31:28.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2016-01-15T01:30:33.000Z (over 10 years ago)
- Last Synced: 2025-02-25T07:17:51.405Z (over 1 year ago)
- Language: JavaScript
- Homepage: https://angular.io/docs/ts/latest/tutorial/
- Size: 9.77 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
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 exportAppComponent.
-
Services postfixed with.service
e.g.hero.service(.ts) should exportHeroService.
-
-
@Componentused 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
providersarray in@Componentmetadata.
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 serviceprovider(only one per instance of app).
-
Injectable go intoconstructor
- 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
ngOnInitLifecycle Hook