🚀🚀Angular 16 Signal in Action With Reactivity🚀🚀

Image
What is Angular Signal? . Angular introduced a Signal as developer preview in angular 16 Before getting into Angular Signal , Angular works in away of change detection. what is Change detection and zone js role in angular? 🌊: Zone.js detects when something happens in the application. 🌊: Zone.js triggers change detection to update the application state. When change detection starts 🔥, the framework goes through all the components in the tree to verify if their state has changed or not and if the new state affects the view. If that’s the case, the DOM part of the component which is affected by the change is updated. This functionality have a significant impact on the performance of the application, Change Detection is How Angular Updates the UI when the state and app changes.This could be some user interaction or some new data changes in the app. Why Angular Signal? What is Reactivity? Making Something happen when there is a Change is Called Reactivity. ...

Angular 17 Features Hint

Image
Angular 17 was released on Nov 2023 Features 1️⃣ Built-in control flow. @if (loggedIn) { The user is logged in } @else { The user is not logged in } 2️⃣. Built-in for loop @for (user of users; track user.id) { {{ user.name }} } @empty { Empty list of users } 2️⃣.Deferrable views @defer { } 3️⃣.New lifecycle hooks. 🔸 afterRender — register a callback to be invoked each time the application finishes rendering. 🔸 afterNextRender — register a callback to be invoked the next time the application finishes rendering @Component({ selector: 'my-chart-cmp...

Angular 15+ New Way of Functional Router Guards

Image
🔸In Angular v14.2, angular team announced New Router API for standalone. 🔸Functional router guards in Angular allow you to define guards using functions instead of classes. 🔸This can be particularly useful when you want to keep your code concise and avoid creating separate guard classes. Here's how you can use functional router guards in Angular: 🔸Before Angular 15, We need to do Implement Guard with CanActivate and to do the logic inside the guard as class. Angular 15 below. @Injectable() export class AuthGuard implements CanActivate { constructor(private authServices: AuthService, private router: Router, private alertify: AlertifyService) {} canActivate(): Observable | Promise | boolean { if (this.authServices.loggedIn()) { return true; } this.alertify.error('You need to be loggin to acces this area'); this.router.navigate(['/home']); return false; } } Activate in guard ...

Angular - How to Create Custom Elements in Angular

Image
Angular allows you to create custom elements using the Angular Elements package. Angular Elements is a set of Angular directives that helps you convert Angular components into reusable custom elements (also known as web components). This enables you to use Angular components in non-Angular applications or frameworks. Here are the general steps to create a custom element using Angular: Install Angular Elements: Make sure you have Angular CLI installed, and then install Angular Elements using the following command: ng add @angular/elements. Create an Angular Component: Create a new Angular component using the Angular CLI or manually. For example, let's create a simple component named MyCustomElement: ng generate component my-custom-element Register the Component as a Custom Element: In the component file (my-custom-element.component.ts), you need to use the createCustomElement function from @angular/elements to create a cus...

Angular, view encapsulation

Image
Angular View Encapsulation In Angular, view encapsulation is a mechanism that helps to isolate the styles of a component to prevent them from affecting other components in the application. Angular uses a concept called "Shadow DOM" for view encapsulation, but it also provides other strategies. There are three types of view encapsulation in Angular: Features Emulated ...

Angular versions and history - Node compatablity

Image
Angular CLI version Angular version Node.js version TypeScript version RxJS version 1.0.0-beta.17 (package name: angular-cli) ~2.0.2 ^6.9.5 ~2.0.10 ^5.0.3 1.0.0-beta.20-1 (package name: angular-cli) ~2.1.2 ^6.9.5 ~2.0.10 ^5.0.3 1.0.0-beta.22-1 (package name: angular-cli) ~2.2.4 ^6.9.5 ~2.0.10 ^5.0.3 1.0.0-beta.30 ~2.3.1 ^6.9.5 ~2.0.10 ^5.0.3 1.0.0-rc.4 ~2.4.10 ^6.9.5 ...

Angular js vs Angular

Angular js vs Angular AngularJS and Angular are both web development frameworks, but they differ significantly in terms of architecture, features, and design principles. Here's a brief comparison between AngularJS (often referred to as Angular 1.x) and Angular (commonly known as Angular 2 and later versions): Architecture: AngularJS: It follows the MVC (Model-View-Controller) architecture. However, the architecture of AngularJS is often considered more like MVVM (Model-View-ViewModel) due to its two-way data binding. Angular: It is based on a component-based architecture. It uses a hierarchy of components with a clear separation of concerns. The architecture is more modular and follows a unidirectional data flow. Two-way Data Binding: AngularJS: It features two-way data binding, which means changes in the model automatically reflect in the view and vice versa. Angular: While Angular supports two-way data binding, it emphasizes a more controlled approach, providing ways ...

CanActivate Guard In Angular.

The CanActivate guard interface in Angular is used to determine if a route can be activated. It is typically used to protect routes that require authentication or certain conditions to be met before allowing access. import { Injectable } from '@angular/core'; import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree, Router } from '@angular/router'; import { Observable } from 'rxjs'; import { AuthService } from './auth.service'; @Injectable({ providedIn: 'root' }) export class AuthGuard implements CanActivate { constructor(private authService: AuthService, private router: Router) {} canActivate( next: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable | Promise | boolean | UrlTree { if (this.authService.isLoggedIn()) { return true; // Allow access to the route } else { // Redirect to the login page and return false to prevent access to the route ...