Table des matières

Angular

Angular client

https://cli.angular.io/

Doc

Angular with Pug

https://medium.com/@MarkPieszak/using-pug-or-jade-templates-with-the-angular-cli-9e37334db5bc

Ressources

https://blog.angularindepth.com/

https://material.angular.io/components/categories

test dialog: https://stackblitz.com/edit/angular-sqspai?file=app%2Fdialog-overview-example-dialog.html

Tri table example

http://embed.plnkr.co/4eXHag

Data binding

[(ngModel)] Two-way data binding.
[property] Property binding.
(event) Event binding

Interpolation

{{variable}} interpolation. Les deux formes ci-dessous sont équivalentes:

Property binding [property]

It flows a value in one direction, from a component's data property into a target element property.

You cannot use property binding to pull values out of the target element.

You can't bind to a property of the target element to read it. You can only set it.

Event binding (event)

Les deux formes ci-dessous sont équivalentes:

two-way data binding [(ngModel)]

You often want to both display a data property and update that property when the user makes changes.

Template reference variables ( #var )

variable locale qui peut être utilisée par la suite :

<input #phone placeholder="phone number">

<!-- phone refers to the input element; pass its `value` to an event handler -->
<button (click)="callPhone(phone.value)">Call</button>

Directives structurelles

*ngIf

Micro syntax:

<div *ngIf="hero" class="name">{{hero.name}}</div>

Equivallent full syntax:

<ng-template [ngIf]="hero">
  <div class="name">{{hero.name}}</div>
</ng-template>

*ngFor

Micro code:

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

Equivalent full syntax:

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

ngSwitch

Micro code:

<div [ngSwitch]="hero?.emotion">
  <app-happy-hero    *ngSwitchCase="'happy'"    [hero]="hero"></app-happy-hero>
  <app-sad-hero      *ngSwitchCase="'sad'"      [hero]="hero"></app-sad-hero>
  <app-confused-hero *ngSwitchCase="'app-confused'" [hero]="hero"></app-confused-hero>
  <app-unknown-hero  *ngSwitchDefault           [hero]="hero"></app-unknown-hero>
</div>

Equivalent full syntax:

<div [ngSwitch]="hero?.emotion">
  <ng-template [ngSwitchCase]="'happy'">
    <app-happy-hero [hero]="hero"></app-happy-hero>
  </ng-template>
  <ng-template [ngSwitchCase]="'sad'">
    <app-sad-hero [hero]="hero"></app-sad-hero>
  </ng-template>
  <ng-template [ngSwitchCase]="'confused'">
    <app-confused-hero [hero]="hero"></app-confused-hero>
  </ng-template >
  <ng-template ngSwitchDefault>
    <app-unknown-hero [hero]="hero"></app-unknown-hero>
  </ng-template>
</div>

Input and Output properties

An Input property is a settable property annotated with an @Input() decorator. Values flow into the property when it is data bound with a property binding [property].

Exemple:

An Output property is an observable property annotated with an @Output() decorator. The property almost always returns an Angular EventEmitter. Values flow out of the component as events bound with an event binding (event).

Components

Remember that all components are directives.

Directives

There are three kinds of directives in Angular:

Testing

https://psamsotha.github.io/angular/2016/12/16/angular2-testing-karma-systemjs.html

https://jasmine.github.io/api/edge/matchers.html

https://github.com/mgechev/angular-performance-checklist

https://blog.oasisdigital.com/2017/angular-runtime-performance-guide/

Exemples et tests

https://stackblitz.com/edit/ng-countdown-timer

https://stackblitz.com/edit/ng-material-dialog-test