This file contains hidden or 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
| // Signal-based transformation | |
| disabled = input(false, { | |
| transform: (value: boolean | string) => typeof value === 'string' ? value === '' : value | |
| }); |
This file contains hidden or 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 options = signal(['A', 'B', 'C']); | |
| // The selected option resets to the first item whenever 'options' changes | |
| const selectedOption = linkedSignal({ | |
| source: options, | |
| computation: (newOptions) => newOptions[0] | |
| }); | |
| // User can still manually change it | |
| selectedOption.set('B'); |
This file contains hidden or 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 { bootstrapApplication } from '@angular/platform-browser'; | |
| import { provideExperimentalZonelessChangeDetection } from '@angular/core'; | |
| import { AppComponent } from './app/app.component'; | |
| bootstrapApplication(AppComponent, { | |
| providers: [ | |
| provideExperimentalZonelessChangeDetection() | |
| ] | |
| }); |
This file contains hidden or 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
| @switch (userRole) { | |
| @case ('admin') { <admin-panel /> } | |
| @case ('editor') { <editor-tools /> } | |
| @default { <reader-view /> } | |
| } |
This file contains hidden or 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
| @for (item of items; track item.id) { | |
| <li>{{ item.name }}</li> | |
| } @empty { | |
| <li>No items found in the list.</li> | |
| } |
This file contains hidden or 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 (user.isLoggedIn) { | |
| <p>Welcome back, {{ user.name }}!</p> | |
| } @else if (user.isGuest) { | |
| <p>Please sign up.</p> | |
| } @else { | |
| <p>Identify yourself.</p> | |
| } |
This file contains hidden or 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 { signal, computed } from '@angular/core'; | |
| // Define a signal | |
| count = signal(0); | |
| // Define a derived/computed value | |
| doubleCount = computed(() => this.count() * 2); | |
| // Update the signal | |
| increment() { |
This file contains hidden or 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 { bootstrapApplication } from '@angular/platform-browser'; | |
| import { AppComponent } from './app/app.component'; | |
| import { provideRouter } from '@angular/router'; | |
| import { routes } from './app/app.routes'; | |
| import { provideHttpClient } from '@angular/common/http'; | |
| bootstrapApplication(AppComponent, { | |
| providers: [ | |
| provideRouter(routes), // Configures Routing | |
| provideHttpClient(), // Configures HTTP Client |
This file contains hidden or 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
| @Pipe({ name: 'exponentialStrength' }) | |
| export class ExponentialStrengthPipe implements PipeTransform { | |
| transform(value: number, exponent: number): number { | |
| return Math.pow(value, exponent); | |
| } | |
| } |
This file contains hidden or 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
| constructor(private dataService: DataService) { } |
NewerOlder