wangbinyq / personal-wiki

2 stars 0 forks source link

ng #24

Open wangbinyq opened 5 years ago

wangbinyq commented 5 years ago

Decortaor pattern

Rx pattern

Component

Template

wangbinyq commented 5 years ago

Form

Reactive

Template

Validate

wangbinyq commented 5 years ago

Decorator Pattern

wangbinyq commented 5 years ago

Directive

Component

Attribute Component

Structural Component

Angular's NgIf, Else, Then - Explained Angular ngFor, and the compiler

<ng-template [ngIf]="hero">

{{hero.name}}

<div *ngFor="let hero of heroes; let i=index; let odd=odd; trackBy: trackById" [class.odd]="odd"> ({{i}}) {{hero.name}}

<ng-template ngFor let-hero [ngForOf]="heroes" let-i="index" let-odd="odd" [ngForTrackBy]="trackById"> <div [class.odd]="odd">({{i}}) {{hero.name}}


- `ng-template`: not render
- `ng-container`: group elements
wangbinyq commented 5 years ago

Dependency Injection

Mastering Angular dependency injection with @Inject, @Injectable, tokens and providers

Injectable

export type InjectableProvider = ValueSansProvider | ExistingSansProvider |
    StaticClassSansProvider | ConstructorSansProvider | FactorySansProvider | ClassSansProvider;

export interface InjectableDecorator {
  /**
   * A marker metadata that marks a class as available to `Injector` for creation.
   *
   * For more details, see the ["Dependency Injection Guide"](guide/dependency-injection).
   *
   * @usageNotes
   * ### Example
   *
   * {@example core/di/ts/metadata_spec.ts region='Injectable'}
   *
   * `Injector` will throw an error when trying to instantiate a class that
   * does not have `@Injectable` marker, as shown in the example below.
   *
   * {@example core/di/ts/metadata_spec.ts region='InjectableThrows'}
   *
   */
  (): any;
  (options?: {providedIn: Type<any>| 'root' | null}&InjectableProvider): any;
  new (): Injectable;
  new (options?: {providedIn: Type<any>| 'root' | null}&InjectableProvider): Injectable;
}

export const Injectable: InjectableDecorator = makeDecorator(
    'Injectable', undefined, undefined, undefined,
    (type: Type<any>, meta: Injectable) => SWITCH_COMPILE_INJECTABLE(type as any, meta));

Hierarchical Dependency Injectors

Provider

wangbinyq commented 5 years ago

Change Detection

Understanding Change Detection Strategies in Angular