Annotations: TypeScript is statically typed and, therefore, all checks are performed at compile time. As mentioned before Types are annotated using :TypeAnnotation syntax.
let isDone: boolean = false;
@Component({ | |
selector: 'my-app', | |
templateUrl: './app.component.html', | |
}) | |
export class AppComponent { | |
form = this.formBuilder.group({ | |
firstName: [''], | |
lastName: [''], | |
age: [''], | |
}); |
Property | |
<img [src]="heroImageUrl"> | |
<app-hero-detail [hero]="currentHero"></app-hero-detail> | |
<div [ngClass]="{'special': isSpecial}"></div> | |
Event | |
<button (click)="onSave()">Save</button> |
/* | |
{ | |
"goodPackage": { | |
"upsellList": [ | |
{ | |
"productCode": "product1" | |
} | |
] |
import { Directive, Input, ElementRef, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appNumbersOnly]' | |
}) | |
export class NumbersOnlyDirective { | |
@Input() fieldMaxLength: number; | |
constructor(private _el: ElementRef) { } | |
@HostListener('keypress', ['$event']) onkeypress(event) { |
import { Directive, ElementRef, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appFocusfirstInvalidfield]' | |
}) | |
export class FocusfirstInvalidfieldDirective { | |
constructor(private el: ElementRef) { } | |
@HostListener('submit', ['$event']) |
import { Directive, HostListener } from '@angular/core'; | |
@Directive({ | |
selector: '[appBlockCopyPaste]' | |
}) | |
export class BlockCopyPasteDirective { | |
constructor() { } | |
@HostListener('paste', ['$event']) blockPaste(e: KeyboardEvent) { | |
e.preventDefault(); |
public onlineOffline: boolean = navigator.onLine; | |
constructor(.......) | |
................ | |
................ | |
ngOnInit() { | |
window.addEventListener('online', () => { | |
this.onlineOffline = true; | |
}); |