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
// Avoid useless computations and combine the property and its initialization method | |
// Live demo at stackblitz.com/edit/angular-lazy-getter | |
import { Component, ChangeDetectionStrategy } from '@angular/core'; | |
import { LazyGetter } from 'lazy-get-decorator'; | |
@Component({ | |
selector: 'lazy-getter-usage', | |
template: ` | |
<h1>{{ sayHelloWithLazyGetter }}</h1> | |
<h1>{{ sayHelloWithoutLazyGetter() }}</h1> |
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
// A safe way to call methods in templates | |
// Live demo @ https://stackblitz.com/edit/angular-generic-map-pipe | |
import { Pipe, PipeTransform } from "@angular/core"; | |
// Methods passed to the map pipe cannot (and should not) use the `this` keyword from components. Otherwise, it would not be a pure pipe. | |
@Pipe({ name: "map" }) | |
export class MapPipe implements PipeTransform { | |
public transform<T, R>( | |
thisArg: T, | |
project: (t: T, ...others: any[]) => R, |
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
// With "+" operator | |
1 + undefined | |
// NaN | |
undefined + undefined | |
// NaN | |
"1" + "2" | |
// "12" |