View ng-store-05.html
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
<ngs-container [query$]="query$" | |
[data$]="pokemons$"> | |
<ng-template let-pokemons> | |
<div *ngFor="let p of pokemons; trackBy: trackByValue">{{ p.name }}</div> | |
</ng-template> | |
</ngs-container> |
View ng-store-04.ts
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 { NgFor } from '@angular/common'; | |
import { ChangeDetectionStrategy, Component, inject, TrackByFunction } from '@angular/core'; | |
import { NgStore, NgStoreModule, trackByValue } from '@ssougnez/ng-store'; | |
import { map, Observable } from 'rxjs'; | |
import { Pokemon } from './models/pokemon.model'; | |
import { PokemonService } from './services/pokemon.service'; | |
import { AppState } from './state/app.state'; | |
@Component({ | |
selector: 'app-root', |
View ng-store-03.ts
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 { inject, Injectable } from "@angular/core"; | |
import { NgStore } from "@ssougnez/ng-store"; | |
import { Observable } from "rxjs"; | |
import { Pokemon } from "../models/pokemon.model"; | |
import { AppState } from "../state/app.state"; | |
@Injectable({ | |
providedIn: 'root' | |
}) | |
export class PokemonService { |
View ng-store-02.ts
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 { createEntities, Entities } from "@ssougnez/ng-store"; | |
import { Pokemon } from "../models/pokemon.model"; | |
export type AppState = { | |
pokemons: Entities<Pokemon>; | |
} | |
export const initial: AppState = { | |
pokemons: createEntities<Pokemon>([], ['type']) | |
} |
View ng-store-01.ts
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 { BaseEntity } from "@ssougnez/ng-store"; | |
export type Pokemon = BaseEntity<number> & { | |
name: string; | |
type: 'water' | 'fire' | 'electric' | 'grass' | 'bug' | 'normal' | 'poison'; | |
} |
View html-directive-06.ts
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
if (element.tagName === 'A') { | |
const href: string = element.href?.toLowerCase(); | |
if (href?.startsWith(location.origin.toLowerCase())) { | |
element.addEventListener('click', (e: MouseEvent) => { | |
this._router.navigate([href.substring(location.origin.length)]); | |
e.preventDefault(); | |
}); | |
} | |
} |
View html-directive-05.ts
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
const descandants = this._elementRef.nativeElement.querySelectorAll('*'); | |
for (const element of descandants) { | |
element.setAttribute(this._uniqueId, ''); | |
... | |
} |
View html-directive-04.ts
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
this._elementRef.nativeElement.innerHTML = this.html; |
View html-directive-03.ts
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
this._uniqueId ||= [...this._elementRef.nativeElement.attributes].find( | |
(attr) => attr.name.startsWith('_ngcontent-') | |
).name; |
View html-directive-02.ts
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 { Directive, ElementRef, Input, OnChanges } from '@angular/core'; | |
import { Router } from '@angular/router'; | |
@Directive({ | |
selector: '[html]', | |
}) | |
export class HtmlDirective implements OnChanges { | |
private _uniqueId: string; | |
@Input() |
NewerOlder