Grandgular [Angular]
157 subscribers
42 photos
1 video
18 links
All about πŸ…°οΈngular: regular tips, best practices, tricks, news, events, performance, and architecture.

🀝 We share experience, discuss, and grow together.

Grandgular. Focus on the small things.
Download Telegram
'mergeMap' Unlocked: Mastering Concurrency in RxJS

You know mergeMap, concatMap, exhaustMap, and switchMap - but did you know only one of them accepts a second argument?

πŸ‘‰ mergeMap stands out with its optional concurrent parameter that limits parallel subscriptions. Think of it as a "concurrency throttle" for your Observables.
_

Use Case (Controlled API Polling):

Imagine you're building a dashboard that needs to:
1️⃣ Process multiple files
2️⃣ Avoid browser/API overload
3️⃣ Maintain upload order

And in this case, the second argument of mergeMap will come in handy as never before:


from(fileList).pipe(
mergeMap(
file => uploadFile(file), // upload fn
3 // upload only 3 files at a time
)
).subscribe();

_

Key benefits of concurrent mergeMap:
βœ… Prevents API flooding
βœ… Balances network load
βœ… Keeps UI responsive
_

Did you know about this hidden gem? πŸ˜‰

#Angular
#RxJS #JavaScript #WebDev #FrontEnd #Performance
1πŸ”₯4
🌐 Angular Events (JUNE)

Don’t miss these awesome Angular meetups and conferences happening this June!

πŸ“ 3 June – Paris Angular Meetup
πŸ“ 4 June – AngularNYC
πŸ“ 12 June – Angular.love Spring Camp
πŸ“ 12 June – Angular Meetup Graz
πŸ“ 19-20 June – NGRome
πŸ“ 26 June – Dutch Angular Group

I’ve picked my event - joining Angular.love Spring Camp on June 12th! What about you?

#Angular #WebDev #JavaScript #TechCommunity #Meetup
1πŸ”₯3πŸ‘2
πŸ¦₯ RxJS defer β€” Lazy Observable Initialization

defer is a factory that creates an Observable only upon subscription, not at declaration time. Perfect for:
β€’ HTTP requests (to avoid premature execution),
β€’ dynamic data (that must be fresh on each subscription),
β€’ conditional streams (when the Observable depends on runtime state).

πŸ“Œ Key Use Cases
1. Fresh Data on Every Subscription

const freshData$ = defer(() => of(Date.now()));
// New timestamp on every subscribe()


2. Working with Mutable State

const token$ = defer(() => of(localStorage.getItem('token')));
// Always gets the current token, even if updated


3. Conditional Observables

const api$ = defer(() =>
isLoggedIn ? http.get('/user') : http.get('/guest')
);


4. Random Value Generation

const random$ = defer(() => of(Math.random()));
// New random number per subscription


🚫 Limitations of defer
β€’ No caching β†’ use shareReplay if you need to reuse results.
β€’ No request cancellation β†’ combine with switchMap/takeUntil for cancellation control.

⚑When to Choose defer Over Regular Observables?
β€’ data must be fresh on every subscribe().
β€’ Observable creation is expensive and should be deferred.
β€’ the stream depends on mutable conditions (feature flags, auth status etc.).

"Do you know other interesting use cases? Share in the comments!"

#rxjs #javascript #webdev #frontend #angular
1πŸ‘3πŸ‘2
πŸŽ‰πŸŽ‰πŸŽ‰ Angular v20 is here! πŸŽ‰πŸŽ‰πŸŽ‰

As of May 29, 2025, the stable release of Angular 20 is officially out!

πŸ†• Highlights (from the article):
- Promoting reactivity features to stable
- New, experimental APIs
- Promoting Zoneless to developer preview
- Solidifying Angular on the server
- and many more...

Useful Links:
πŸ”— Angular v20 Release on GitHub
https://github.com/angular/angular/releases/tag/20.0.0
πŸ“ Official Release Blog
https://blog.angular.dev/announcing-angular-v20-b5c9c06cf301
πŸ“† Release & Support Schedule
https://angular.dev/reference/releases
πŸ“¦ Angular CLI v20 Release Notes
https://www.gitclear.com/open_repos/angular/angular-cli/release/20.0.0-next.0

#angular #angular20 #webdev #frontend #JavaScript #TypeScript
1πŸ”₯5πŸ‘3
`withComponentInputBinding()`
Simplifying work with router parameters in Angular.

How was it before?

1. Create a variable/property (Signal, BehaivorSubject, Observable, doesn't matter)
2. Inject and subscribe to ActivatedRoute
3. Get the route parameters
4. Write to BS/Signal

πŸ˜΅β€πŸ’«πŸ˜΅β€πŸ’«πŸ˜΅β€πŸ’«

There are quite a lot of manipulations, but we've all gotten used to it and it seems ok. But with withComponentInputBinding(), everything has become much simpler:

1. Create a signal input... and...

That's it!
No extra manipulations and the value is 'in your pocket'. All you need for this to work is to pass wCIB() as an argument to provideRouter().

The feature is not new (it seems to have appeared in Angular 16), but I've rarely seen it in projects.

A bit of technical information from the docs:

The router passes data to input() from:
1. Query parameters (?page=1&sort=asc)
2. Path and matrix parameters (/users/123;details=true)
3. Static route data (data: { role: 'admin' })
4. Resolver results (resolve: { user: userResolver })

πŸ” Priorities:
If there are duplicate keys, the data is redefined in the order above β€” resolvers have the highest priority and will overwrite the rest.

🚩 Important nuance
If there is no data for input() in the route, it will receive undefined (for example, if the query parameter is removed from the URL).

ℹ️How to set default values?
βœ” Through a resolver (so that the data is always in the route)
βœ” Through transform in input() (if you need to handle undefined)

Thanks to the Angular developers for this functionality πŸ™. God bless them.

#angular #webdev #frontend #JavaScript #TypeScript
Please open Telegram to view this post
VIEW IN TELEGRAM
1πŸ‘6πŸ‘Œ2
πŸš€ Introducing @grandgular/link - The Missing Piece for Angular SEO!

The Problem:
Angular provides built-in Title and Meta services, but mysteriously lacks a solution for managing html <link> tags. Until now, developers had to manipulate the DOM manually πŸ˜•

The Solution:
Meet the Link service - a perfect counterpart to Angular's Meta, but for `html
<link>` elements:


constructor(private link: Link) {}

ngOnInit() {
// Add canonical link
this.link.addTag({
rel: 'canonical',
href: 'https://your-site.com/page'
});

// Update on route changes
this.link.updateTag({
rel: 'canonical',
href: 'https://your-site.com/new-url'
});

// etc.
}


πŸ”₯ Key Benefits:
- Full TypeScript support
- Familiar Angular-style API (just like Meta)
- Supports all standard <link> attributes
- SSR-ready out of the box
- Tiny footprint (~2KB)

Works perfectly as a standalone solution - no dependency on our upcoming SEO suite.

πŸ“¦ NPM: https://www.npmjs.com/package/@grandgular/link
πŸ’» GitHub: https://github.com/Grandgular/link

P.S. This is the first building block in our comprehensive Angular SEO toolkit. What features would you like to see in the full solution?
Let us know in the comments! πŸ‘‡

#Angular #SEO #WebDev #Frontend #JavaScript
7πŸ‘6πŸ”₯3😱2πŸ‘1
⏰ Timeouts for HTTP in Angular.

A common practice is to create a wrapper around the HttpClient that is used throughout the project. It often handles tasks like timeouts and retry logic using operators like .pipe(timeout(8000)).

But this solution isn't the most elegant - it adds an extra layer and boilerplate.

What if such a wrapper service doesn't exist in the project, but you need to solve the timeout issue right now?

I believe the most graceful option is to add custom functionality directly to provideHttpClient(). For example, something like withTimeout (look at the picture + code in the comments)

🎯 What does it offer?

- A global timeout default for all requests
- Flexible rules for specific endpoints
- Clean and readable code without repetitive boilerplate and extra layers.
- All timed-out requests fail with a 408 TimeoutError.

πŸ’‘ Using the same principle, you can do the following: withRetry(), withRateLimiting(), withErrorHandler(), etc.

#angular #frontend #javascript #typescript #webdev
7πŸ”₯6πŸ‘Œ1