programming:angular
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
programming:angular [2023/07/26 05:56] – skipidar | programming:angular [2023/11/01 07:31] (current) – ↷ Page moved from camunda:programming:angular to programming:angular skipidar | ||
---|---|---|---|
Line 16: | Line 16: | ||
== let == | == let == | ||
- | use ''' | + | use '' |
- | Dont use ''' | + | Dont use '' |
- | Typescript resolves the conflicts between scopes on its own, when using ''' | + | Typescript resolves the conflicts between scopes on its own, when using '' |
Line 163: | Line 163: | ||
Watch changes in code and auto rebuild | Watch changes in code and auto rebuild | ||
+ | < | ||
+ | ng build --watch --poll 500 --configuration development | ||
+ | </ | ||
+ | |||
+ | To check if any module in a project is ' | ||
+ | |||
+ | To update all dependencies, | ||
+ | |||
+ | To update all dependencies, | ||
+ | |||
+ | To update package.json version numbers, append the --save flag: '' | ||
< | < | ||
ng build --watch --poll 500 --configuration development | ng build --watch --poll 500 --configuration development | ||
Line 391: | Line 402: | ||
- | TypeScript eliminates this boilerplate of using '''" | + | TypeScript eliminates this boilerplate of using ''" |
accessors on the constructor parameters. | accessors on the constructor parameters. | ||
Line 761: | Line 772: | ||
A new **component** " | A new **component** " | ||
- | ''' | + | '' |
<sxh ts> | <sxh ts> | ||
import {Component, Input} from ' | import {Component, Input} from ' | ||
Line 783: | Line 794: | ||
Because a field " | Because a field " | ||
- | ''' | + | '' |
<sxh ts> | <sxh ts> | ||
Line 792: | Line 803: | ||
- | ''' | + | '' |
Define a " | Define a " | ||
Line 814: | Line 825: | ||
And I bind the title field of root component to it. | And I bind the title field of root component to it. | ||
- | ''' | + | '' |
<sxh ts> | <sxh ts> | ||
< | < | ||
Line 825: | Line 836: | ||
A new **component** " | A new **component** " | ||
- | ''' | + | '' |
<sxh ts> | <sxh ts> | ||
import {Component, Input} from ' | import {Component, Input} from ' | ||
Line 846: | Line 857: | ||
Because a field " | Because a field " | ||
- | ''' | + | '' |
<sxh html> | <sxh html> | ||
Line 875: | Line 886: | ||
And I bind the '' | And I bind the '' | ||
- | ''' | + | '' |
<sxh ts> | <sxh ts> | ||
< | < | ||
Line 1161: | Line 1172: | ||
... | ... | ||
+ | </ | ||
+ | |||
+ | |||
+ | The component stub can be generated. | ||
+ | |||
+ | Also under a " | ||
+ | |||
+ | |||
+ | < | ||
+ | ng generate component heroes/ | ||
</ | </ | ||
Line 1311: | Line 1332: | ||
</ | </ | ||
- | | + | |
- | the module. | + | |
- | * imports: Other modules that contain declarations to be used by this module. | + | * imports: Other modules that contain declarations to be used by this module. The Angular CLI defines CommonModule automatically for us in this property. It is a module that is always used in Angular applications because it contains all the built-in directives and pipes that we usually would like to use. Be careful not to get caught in circular references when you import a module that already imports yours. |
- | The Angular CLI defines CommonModule automatically for us in this property. It | + | * exports: Angular artifacts that are defined in declarations and are available for other modules to use. This is the public API of the module. It defines what is publicly accessible or not. Everything else that's not explicitly exported would be considered private or internal to the module. |
- | is a module that is always used in Angular applications because it contains all the | + | * providers: Services that are provided from the module and are accessible from any module of the application. We'll learn more about providers in the How dependency injection works in Angular section. |
- | built-in directives and pipes that we usually would like to use. Be careful not to get | + | * bootstrap: The main component of the application that will be rendered when the application starts up. This property is set only once in the main application module, AppModule, and is usually AppComponent. Typically, you should not change it unless there is a particular reason to do so. |
- | caught in circular references when you import a module that already imports yours. | + | |
- | * exports: Angular artifacts that are defined in declarations and are available | + | |
- | for other modules to use. This is the public API of the module. It defines what is | + | |
- | publicly accessible or not. Everything else that's not explicitly exported would be | + | |
- | considered private or internal to the module. | + | |
- | * providers: Services that are provided from the module and are accessible | + | |
- | from any module of the application. We'll learn more about providers in the | + | |
- | How dependency injection works in Angular section. | + | |
- | * bootstrap: The main component of the application that will be rendered when | + | |
- | the application starts up. This property is set only once in the main application | + | |
- | module, AppModule, and is usually AppComponent. Typically, you should not | + | |
- | change it unless there is a particular reason to do so. | + | |
Line 1521: | Line 1530: | ||
More: https:// | More: https:// | ||
+ | |||
+ | |||
+ | |||
+ | ===== Async patterns ===== | ||
+ | |||
+ | |||
+ | == Promises == | ||
+ | |||
+ | * They cannot be canceled. | ||
+ | * They are immediately executed. | ||
+ | * They are one-time operations only; there is no easy way to retry them. | ||
+ | * They respond with only one value. | ||
+ | |||
+ | |||
+ | <sxh ts> | ||
+ | private onComplete() { | ||
+ | return new Promise((resolve, | ||
+ | | ||
+ | | ||
+ | }, 2000); | ||
+ | }); | ||
+ | } | ||
+ | |||
+ | |||
+ | private setTitle = () => { | ||
+ | this.title = 'Hello Angular 10'; | ||
+ | } | ||
+ | |||
+ | constructor() { | ||
+ | this.onComplete().then(this.setTitle); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | == Observers == | ||
+ | |||
+ | |||
+ | |||
+ | <sxh ts> | ||
+ | |||
+ | // triggers every 2 sec his observables | ||
+ | title$ = new Observable(observer => { | ||
+ | setInterval(() => { | ||
+ | observer.next(); | ||
+ | }, 2000); | ||
+ | }); | ||
+ | |||
+ | |||
+ | private setTitle = () => { | ||
+ | const timestamp = new Date().getMilliseconds(); | ||
+ | this.title = `Hello Angular 10 (${timestamp})`; | ||
+ | } | ||
+ | |||
+ | constructor() { | ||
+ | this.title$.subscribe(this.setTitle); | ||
+ | } | ||
+ | </ |
programming/angular.1690351003.txt.gz · Last modified: by skipidar