Skip to content

Dace Zarina angular training #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open

Conversation

dacezarina
Copy link

Pull request

export const appRoutes: Routes = [];
export const appRoutes: Routes = [
{ path: '', redirectTo: '/blog-posts', pathMatch: 'full' },
{ path: 'blog-posts', component: PostsPageComponent },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a good practice it is to use lazy loading for routes. In this case it will break bundle into chunks that will be loaded only on a first visit of route. This may significantly improve first loading times especially for bigger applications.

   path: 'blog-posts',
    // ↓ PostsPageComponentis now lazy loaded
    loadComponent: () => import('./path/to/posts-page.component').then(m => m.PostsPageComponent),


<main>
<router-outlet></router-outlet>
<div *ngIf="!route.firstChild">
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@if (Control Flow syntax) can be used everywhere. In this case you probably may get rid of CommonModule import in component, but this approach is also correct. just FYI.

@Component({
selector: 'app-guest-form',
templateUrl: './guest-form.component.html',
standalone: true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Angular 19 standalone = true is default so can be not added, but its not a mistake.

private avatarService: AvatarService
) {
if (this.entry$ != undefined) {
this.entry$.subscribe(entry => {
Copy link

@up-ctc up-ctc May 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When you have a subscription you should always unsubscribe from it when component is destroyed. Otherwise it may lead to memory leaks and unwanted effects when this component is opened.

private subscriptions = new Subscription();
 
public ngOnInit() {
	this.subscriptions.add(
		this.service.yourObservableReturningFunction().subscribe(...)
	)
}
 
public ngOnDestroy() {
	this.subscriptions.unsubscribe();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants