This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form [formGroup]="form"> | |
<mat-form-field> | |
<input matInput type="text" formControlName="num" placeholder="The Number"> | |
<mat-hint>Example 40</mat-hint> | |
<mat-error>Please enter a number</mat-error> | |
<mat-error *ngIf="num.errors && num.errors.min">Minimum is 0 | |
</mat-error> | |
<mat-error *ngIf="num.errors && num.errors.isNumber">The value must be a number | |
</mat-error> | |
</mat-form-field> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { FormControl } from '@angular/forms'; | |
export function isNumber(c: FormControl) { | |
return !isNaN(c.value) ? null : { | |
isNumber: { | |
valid: false | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-table class="mat-elevation-z8" [dataSource]="dataSource" matSort> | |
<ng-container matColumnDef="id"> | |
<mat-header-cell *matHeaderCellDef mat-sort-header>ID</mat-header-cell> | |
<mat-cell *matCellDef="let row;">{{row.id}}</mat-cell> | |
</ng-container> | |
<mat-header-row *matHeaderRowDef="displayedColumns"> | |
</mat-header-row> | |
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row> | |
</mat-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<mat-table class="mat-elevation-z8" [dataSource]="dataSource"> | |
<ng-container matColumnDef="id"> | |
<mat-header-cell *matHeaderCellDef>ID</mat-header-cell> | |
<mat-cell *matCellDef="let row;">{{row.id}}</mat-cell> | |
</ng-container> | |
<mat-header-row *matHeaderRowDef="displayedColumns"> | |
</mat-header-row> | |
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row> | |
</mat-table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component } from '@angular/core'; | |
import { FormControl } from '@angular/forms'; | |
import { Observable } from 'rxjs'; | |
@Component({ | |
selector: 'my-app', | |
template: ` | |
<div style="margin: 2rem;"> | |
<div class="input-field"> | |
<i class="material-icons prefix">add_box</i> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ngAfterViewInit() { | |
// server-side search | |
fromEvent(this.input.nativeElement,'keyup') | |
.pipe( | |
filter(Boolean), | |
debounceTime(150), | |
distinctUntilChanged(), | |
tap((text) => { | |
console.log(this.input.nativeElement.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Local Storage State Manager</title> | |
<script type="text/javascript"> | |
let products = JSON.parse(localStorage.getItem('products')); | |
console.log(products); | |
</script> | |
</head> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Local Storage State Manager</title> | |
<script type="text/javascript"> | |
let products = [ | |
{ name: "Impossible Burger", description: "Better than cow!!"}, | |
{ name: "Impossible Chicken", description: "Good!!"} | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { calculateAveragePurchaseCost } from './'; | |
it('should calculate the average purchase cost', ()=>{ | |
let po1 = { sku: 'sk123', purchaseCost: 30000}; | |
let po2 = { sku: 'sk223', purchaseCost: 60000}; | |
let pos = [po1, po2]; | |
let averagePurchaseCost = calculateAveragePurchaseCost(pos); | |
expect(averagePurchaseCost).toEqual(45000); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Calculate the average purchase cost for the array of {@link PurchaseOrder} | |
* instances. | |
* | |
* @param purchaseOrders | |
*/ | |
export function calculateAveragePurchaseCost(purchaseOrders:Partial<PurchaseOrder>[]):number { | |
return (average( | |
purchaseOrders | |
.map(po => po.purchaseCost) |