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 routes: Routes = [ | |
{ path: "dashboard", component: DashboardComponent }, | |
{ | |
path: "profiles", | |
redirectTo: ({ queryParams }) => { | |
const errorHandler = inject(ErrorHandler); | |
const userId = queryParams['userId']; | |
if (userId) { | |
// return the appropriate redirect path based on the userId query-parameter | |
return `/profiles/${userId}`; |
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 routes: Routes = [ | |
{ | |
path: 'route1', | |
component: Route1Component, | |
renderMode: 'stategy1' // renderMode option 1 | |
}, | |
{ | |
path: 'route2', | |
component: Route2Component, | |
renderMode: 'strategy2' // renderMode option 2 |
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 routes: Routes = [ | |
{ | |
path: 'dashboard', | |
component: DashboardComponent, | |
canActivate: [ | |
() => { | |
const router: Router = inject(Router); | |
const urlTree: UrlTree = router.parseUrl('/error'); | |
return new RedirectCommand(urlTree, { skipLocationChange: true }); | |
}, |
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 { FormBuilder, FormGroup, Validators } from '@angular/forms'; | |
export class ProfileFormComponent { | |
private fb = inject(FormBuilder); | |
profileForm: FormGroup; | |
ngOnInit() { | |
this.profileForm = this.fb.group({ | |
firstName: ['', [Validators.required, Validators.minLength(2)]], |
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
@Component({ | |
selector: 'main-layout', | |
template: ` | |
<ng-content select="header">Hello again</ng-content> | |
<ng-content><p>Default content if none is provided.</p></ng-content> | |
<ng-content select="footer"></ng-content> | |
` | |
}) | |
export class MainLayoutComponent {} |
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, model, input } from '@angular/core'; | |
@Component({ | |
selector: 'app-user', | |
template: '<button (click)="upgradeSubscription()">Upgrade Subscription</button>', | |
}) | |
export class UserComponent { | |
// a standard input, it's read-only | |
isSubscribed = input(true); |
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 { bootstrapApplication } from '@angular/platform-browser'; | |
import { provideExperimentalZonelessChangeDetection } from '@angular/core'; | |
import { AppComponent } from './app/app.component'; | |
bootstrapApplication(AppComponent, { | |
providers: [ | |
provideExperimentalZonelessChangeDetection(), | |
], | |
}); |
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 (isOrganization) { | |
<profile-organization [data]="userData"></profile-organization> | |
} @else if (isPremium) { | |
<profile-premium [data]="userData"></profile-premium> | |
} @else { | |
<profile-basic [data]="userData"></profile-basic> | |
} |
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
# Python handles memory management for you | |
list_of_items = ['item1', 'item2', 'item3'] | |
print("Current list:", list_of_items) | |
# When objects like lists are no longer needed, Python cleans up | |
del list_of_items # This frees up memory space automatically | |
# The garbage collector in Python manages the allocation and deallocation of memory |
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
#include <stdio.h> | |
#include <string.h> | |
void process_command(char *input) { | |
char buffer[30]; | |
strcpy(buffer, input); // Potential overflow here | |
// ... Process command | |
} | |
int main() { | |
char command[100]; |
NewerOlder