π Change Detection in Angular
#angular #signals #cdr
4. Local Change Detection π©Angular 17
β Article link: https://medium.com/ngconf/local-change-detection-in-angular-410d82b38664
#angular #signals #cdr
4. Local Change Detection π©Angular 17
@Component({
selector: 'app-timer',
template: `<span>Last Updated: {{ lastUpdateInSeconds() | number:'1.0-0' }} Seconds</span> {{ logCd() }}`,
standalone: true,
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [DatePipe, DecimalPipe, AsyncPipe]
})
export class TimerComponent {
@Input() lastUpdate = new Date();
lastUpdateInSeconds = signal(0)
constructor() {
setInterval(() => {
this.lastUpdateInSeconds.set((new Date().getTime() - this.lastUpdate.getTime()) / 1_000);
}, 1000);
}
logCd() {
console.log('log from timer');
}
}β Article link: https://medium.com/ngconf/local-change-detection-in-angular-410d82b38664
π₯1π₯°1
π Transitioning to Angular 17βs New Control Flow Syntax
#angular #controlFlow
π© > Angular v17
β Article link: https://medium.com/@dimeloper/transitioning-to-angular-17s-new-control-flow-syntax-0555aa45f06f
#angular #controlFlow
π© > Angular v17
β Article link: https://medium.com/@dimeloper/transitioning-to-angular-17s-new-control-flow-syntax-0555aa45f06f
π₯1
π Exploring the New
#js #groupBy
β Article link: https://medium.com/@bhargavr445/exploring-the-new-object-groupby-function-in-chrome-117-028820848433
Object.groupBy Function in Chrome 117#js #groupBy
β Article link: https://medium.com/@bhargavr445/exploring-the-new-object-groupby-function-in-chrome-117-028820848433
π₯1
π Card Composite via @ViewChildren in Angular
#angular #decorator #ViewChildren
β Article link: https://blog.stackademic.com/card-composite-via-viewchildren-in-angular-aa3317f92f82
#angular #decorator #ViewChildren
Imagine the following requirements for your Angular app:
- Your customer wants a view that displays multiple cards at once.
- A button at the top of the page should toggle the edit mode.
- While in edit mode, all cards are editable at the same time.
- As soon as you click βsaveβ only those cards that actually have been edited are going to send a request to the server.
- If you decide to discard the changes by clicking on βcancelβ all cards should be reset to their initial state.
This is a common scenario in any more sophisticated web application. Nevertheless, I just recently discovered a very handy way to handle those requirements in Angular. In this article I want to share my solution, leveraging the @ViewChildren property decorator to implement the Card Composite pattern.
β Article link: https://blog.stackademic.com/card-composite-via-viewchildren-in-angular-aa3317f92f82
π2π₯1
π Angular Interceptors: Authentication Interceptor
#angular #interceptor
#angular #interceptor
An authentication interceptor is used to add authentication tokens to outgoing requests and handle authentication-related errors. This is essential for securing your applicationβs API requests.
import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
} from '@angular/common/http';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler) {
const authToken = 'your-auth-token';
const authRequest = request.clone({
headers: request.headers.set('Authorization', `Bearer ${authToken}`),
});
return next.handle(authRequest);
}
}π₯2
π Cross-Site Scripting (XSS) Attacks
#angular #xss
β Article link: https://rahuulmiishra.medium.com/mitigating-cross-site-scripting-xss-attacks-best-practices-and-code-examples-a5e4fd9d67a6
#angular #xss
β Article link: https://rahuulmiishra.medium.com/mitigating-cross-site-scripting-xss-attacks-best-practices-and-code-examples-a5e4fd9d67a6
π₯1
π Angular Interceptors: Error Handling Interceptor
#angular #interceptor
#angular #interceptor
An error handling interceptor can be used to centralize error handling for HTTP requests. It can capture HTTP errors, log them, and perform appropriate actions like displaying error messages.
import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
HttpErrorResponse,
} from '@angular/common/http';
import { catchError } from 'rxjs/operators';
import { throwError } from 'rxjs';
@Injectable()
export class ErrorInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler) {
return next.handle(request).pipe(
catchError((error: HttpErrorResponse) => {
// Handle and log the error here
console.error('HTTP Error:', error);
// Optionally rethrow the error to propagate it
return throwError(error);
})
);
}
}π₯2
π Angular Pipes: Uppercase First Pipe
#angular #pipe
Usage in an Angular template:
#angular #pipe
This pipe capitalizes the first letter of a string while keeping the rest in lowercase.
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'uppercaseFirst' })
export class UppercaseFirstPipe implements PipeTransform {
transform(value: string): string {
if (!value) return value;
return value
.charAt(0)
.toUpperCase() + value.slice(1).toLowerCase();
}
}Usage in an Angular template:
<p>{{ 'hello world' | uppercaseFirst }}</p>
<!-- Output: "Hello world" -->β€1π1π₯1
π Downloading a PDF from a BASE64 String in Angular
#angular #pdf #base64
β οΈ The example is for presentation purposes only and can be refactored.
β Article link: https://kalanavw.medium.com/downloading-a-pdf-from-a-base64-string-in-angular-afe50fca1538
#angular #pdf #base64
β οΈ The example is for presentation purposes only and can be refactored.
β Article link: https://kalanavw.medium.com/downloading-a-pdf-from-a-base64-string-in-angular-afe50fca1538
π1
Hello, friends!
As you can see, I'm a Ukrainian software engineer who tries to do volunteer fundraisers to support the Armed Forces of Ukraine. Sometimes it takes a lot of time and I am not able to maintain this channel for you. Please help me close these fundraisers because without the Ukrainian army there will be nothing Ukrainian. Thank you very much!
π΅ FOR Ukraine:
https://send.monobank.ua/jar/5FDvaBP4zn
5375 4114 1222 8582
π FOR ALL DONATS:
π΅ SWIFT code: UNJSUAUKXXX
π΅ PayPal: luckystudydanit@gmail.com
My profile with reports after closing fundraiser :
https://www.facebook.com/volunt2erua/
also all reports in ourπ channel:
https://t.me/toxicc_squad
As you can see, I'm a Ukrainian software engineer who tries to do volunteer fundraisers to support the Armed Forces of Ukraine. Sometimes it takes a lot of time and I am not able to maintain this channel for you. Please help me close these fundraisers because without the Ukrainian army there will be nothing Ukrainian. Thank you very much!
π΅ FOR Ukraine:
https://send.monobank.ua/jar/5FDvaBP4zn
5375 4114 1222 8582
π FOR ALL DONATS:
π΅ SWIFT code: UNJSUAUKXXX
π΅ PayPal: luckystudydanit@gmail.com
My profile with reports after closing fundraiser :
https://www.facebook.com/volunt2erua/
also all reports in our
https://t.me/toxicc_squad
Please open Telegram to view this post
VIEW IN TELEGRAM
β€5π2
π Angular Interceptors: Logging Interceptor
#angular #interceptor
#angular #interceptor
A logging interceptor can be used to log the details of HTTP requests and responses, which is helpful for debugging and monitoring.
import { Injectable } from '@angular/core';
import {
HttpInterceptor,
HttpRequest,
HttpHandler,
HttpResponse,
} from '@angular/common/http';
import { tap } from 'rxjs/operators';
@Injectable()
export class LoggingInterceptor implements HttpInterceptor {
intercept(request: HttpRequest<any>, next: HttpHandler) {
return next.handle(request).pipe(
tap((event) => {
if (event instanceof HttpResponse) {
console.log('HTTP Response:', event);
}
})
);
}
}