Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions apps/angular/21-anchor-navigation/src/app/app.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideRouter, withInMemoryScrolling } from '@angular/router';
import { appRoutes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [provideRouter(appRoutes)],
providers: [
provideRouter(
appRoutes,
withInMemoryScrolling({
anchorScrolling: 'enabled',
scrollPositionRestoration: 'enabled',
}),
),
],
};
10 changes: 7 additions & 3 deletions apps/angular/21-anchor-navigation/src/app/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import { NavButtonComponent } from './nav-button.component';
imports: [NavButtonComponent],
selector: 'app-home',
template: `
<nav-button href="/foo" class="fixed left-1/2 top-3">Foo Page</nav-button>
<nav-button routerLink="/foo" class="fixed left-1/2 top-3">
Foo Page
</nav-button>
<div id="top" class="h-screen bg-gray-500">
Empty
<nav-button href="#bottom">Scroll Bottom</nav-button>
<nav-button routerLink="/home" fragment="bottom">
Scroll Bottom
</nav-button>
</div>
<div id="bottom" class="h-screen bg-blue-300">
I want to scroll each
<nav-button href="#top">Scroll Top</nav-button>
<nav-button routerLink="/home" fragment="top">Scroll Top</nav-button>
</div>
`,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* eslint-disable @angular-eslint/component-selector */
import { Component, input } from '@angular/core';
import { RouterLink } from '@angular/router';

@Component({
selector: 'nav-button',
imports: [RouterLink],
template: `
<a [href]="href()">
<a [routerLink]="routerLink()" [fragment]="fragment()">
<ng-content />
</a>
`,
Expand All @@ -13,5 +15,6 @@ import { Component, input } from '@angular/core';
},
})
export class NavButtonComponent {
href = input('');
routerLink = input('');
fragment = input<string | undefined>(undefined);
}
9 changes: 3 additions & 6 deletions apps/angular/8-pure-pipe/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { Component } from '@angular/core';
import { ShowIndexPipe } from './pipe/show-index.pipe';

@Component({
selector: 'app-root',
imports: [ShowIndexPipe],
template: `
@for (person of persons; track person) {
{{ heavyComputation(person, $index) }}
{{ person | showIndex: $index }}
}
`,
})
export class AppComponent {
persons = ['toto', 'jack'];

heavyComputation(name: string, index: number) {
// very heavy computation
return `${name} - ${index}`;
}
}
10 changes: 10 additions & 0 deletions apps/angular/8-pure-pipe/src/app/pipe/show-index.pipe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
name: 'showIndex',
})
export class ShowIndexPipe implements PipeTransform {
transform(value: string, index: number): string {
return `${value} ${index}`;
}
}
Loading