Skip to main content

Posts

Angular 19 New Feature – linkedSignal, LinkedSignal API

  Angular 19 New Feature – linkedSignal,  LinkedSignal API In Angular 19, linkedSignal allows you to manage and synchronize dependent states efficiently. This feature is especially useful when you have multiple states that rely on each other or need to stay in sync.   Here’s a step-by-step guide with an example of dependent state with linkedSignal in Angular: Scenario Example: You have two signals: selectedCountry - A signal for the selected country. statesForCountry - A signal that depends on the selected country and updates automatically. 1. Import Required Utilities First, ensure you import Angular's reactivity utilities:   import { signal, computed, linkedSignal } from '@angular/core'; 2. Define Signals and Dependent State Use signal for the independent state and linkedSignal to define the dependent state.   Example (location-state.service.ts): import { Injectable, signal, linkedSignal } from '...
Recent posts

Garbage Collection (GC) in C#

Garbage Collection (GC) in C# Garbage Collection (GC) in C# is an automated memory management mechanism provided by the Common Language Runtime (CLR) in the .NET framework. It eliminates the need for developers to manually allocate and free memory, which helps reduce errors such as memory leaks or improper resource cleanup, dangling pointers, or double deletion.   Purpose of Garbage Collection Automatic Memory Management : GC relieves developers from manually deallocating memory, reducing common errors like dangling pointers, memory leaks, or double-free errors. Efficient Resource Utilization : It ensures memory is available for the application by reclaiming unused objects. Key Features of GC Automatic Memory Management : GC automatically deallocates objects no longer in use. Developers only focus on memory allocation, while GC handles deallocation. Managed Heap : All memory allocated fo...

ERROR ReferenceError: localStorage is not defined in Angular 17/18

The error ReferenceError: localStorage is not defined occurs in Angular projects when localStorage is accessed in an environment where it is not available, such as on the server side during server-side rendering (SSR) using Angular Universal. The localStorage API is part of the browser's window object, and it is unavailable in non-browser environments. To fix this error in your Angular 18 project, you can use the following approaches: 1. Check if localStorage Exists Ensure localStorage is accessed only in the browser. Modify your service or component code to check for its availability before using it. if ( typeof window !== 'undefined' && window . localStorage ) { // Access localStorage here localStorage . setItem ( 'key' , 'value' ); } else { console . warn ( 'localStorage is not available.' ); } 2. Use Angular's Dependency Injection for Platform Check Use Angular's PLATFORM_ID to check whether the code is running ...

Call child component method from parent class - Angular

Call child component method from parent class - Angular In Angular, to share data from a child component to a parent component, the most common approach is using EventEmitter with @Output() . Here's how it works step by step: Steps for Child-to-Parent Data Sharing In the Child Component : You define an EventEmitter using the @Output() decorator to emit the data. In the Parent Component : The parent component listens for the event emitted by the child and handles the data that is sent. Example: 1. Child Component ( child.component.ts ) Here, we want to send data (e.g., a message) from the child component to the parent. typescript import { Component , Output , EventEmitter } from '@angular/core' ; @Component ({ selector : 'app-child' , template : ` <button (click)="sendData()">Send Data to Parent</button> ` , styleUrls : [ './child.component.css' ] }) export class ChildComponent { // Step 1: Declare an EventEmitt...

What is the difference between Task and Thread in C#

Both Threads and Task are used for Concurrent and Parallel programming. Thread are scheduled by the Operating system while the Task is scheduled by the TPL (Task parallel Library). Threads offer low-level control but require manual management of synchronization while Tasks provide a higher-level abstraction for asynchronous operations and management are automatically.  Threads is synchronous programming while Task is asynchronous programming using async and await keywords. Threads is a lightweight unit of execution that operates independently of other threads.  Threads require manual exception handling (try-catch block) within the thread and no exception aggregation while Task handle exceptions automatically to the calling code and aggregate multiple exceptions if necessary, using AggregateException for multiple errors.  In general, Tasks provide a more modern, structured way to handle errors, especially when dealing with parallelism or asynchronous programmin...

How to Create, Update, Insert and Delete SQL Views? Is it posible to do?

Yes, it is possible to Create , Update , Insert , and Delete data in SQL Views under certain conditions. SQL views allow you to define a virtual table based on the result of an SQL query. They are useful for simplifying complex queries, providing abstraction, and improving security. 1. Creating a View You can create a view using the CREATE VIEW statement. This defines a virtual table based on a SQL query. Syntax: CREATE VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition ; Example: CREATE VIEW EmployeeView AS SELECT EmployeeID, FirstName, LastName, Department FROM Employees WHERE Department = 'HR' ; 2. Updating a View To modify an existing view, you can use the ALTER VIEW statement. It allows you to change the definition of the view. Syntax: ALTER VIEW view_name AS SELECT column1, column2, ... FROM table_name WHERE condition ; Example: ALTER VIEW EmployeeView AS SELECT EmployeeID, FirstName, LastName, Department, Salary FROM ...