Skip to main content

Posts

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
Recent posts

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 programming  While Thr

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

constructors vs ngOnInit in Angular and .net c# Init

 In Angular, constructors and ngOnInit are both important lifecycle methods, but they serve different purposes and are called at different times. Here's how they work and the order in which they are called: 1. Constructor : The constructor is a method that is invoked first when a component is instantiated. It is used primarily for dependency injection (DI) and initial setup , but it shouldn't contain complex logic or interact with DOM elements since the component isn't fully initialized at this stage. 2. ngOnInit : The ngOnInit() method is part of Angular's component lifecycle hooks and is called after the constructor . It is executed once the component’s input properties are initialized, and is a good place to put logic that depends on the component being fully initialized, like making HTTP requests or setting up component properties based on input values. Order of Execution in Angular: Constructor : Called when the component is created. This is where dependency

forkJoin in Angular 17 | RxJS library

 It seems like you are asking about forkJoin in Angular. forkJoin is a method from the RxJS library that allows you to execute multiple observable requests in parallel and wait for all of them to complete before taking action. What is forkJoin ? forkJoin is commonly used when you need to execute multiple HTTP requests (or other observables) in parallel and only proceed once all the observables have completed. It combines the values emitted by each of the observables into a single array (or object) of results, which you can then process. Key Points About forkJoin : It waits for all observables to complete. It emits the last value of each observable. If one of the observables fails , the entire forkJoin will fail (i.e., it will not emit any value). Usage of forkJoin in Angular To use forkJoin in an Angular application, you typically import it from RxJS and use it within a service or component to manage multiple HTTP requests or other asynchronous operations. Example Scenario:

Dependency Injection vs Factory Pattern

The Factory Design Pattern and Dependency Injection (DI) are both design patterns used to manage object creation and dependencies in software development, but they serve different purposes and are used in different contexts. Here's a detailed comparison: Factory Design Pattern : Purpose : Handles object creation. Focus : Centers on how objects are created. Responsibility : The factory class is responsible for creating objects. Coupling : Can result in tighter coupling between the client and the factory. Control : The factory controls which objects are created. When to Use : When object creation is complex or requires abstraction. Testability : Less test-friendly, as it can tightly couple creation logic to the client. Dependency Injection (DI) : Purpose : Provides dependencies to a class. Focus : Centers on how dependencies are provided. Responsibility : The DI container or framework is responsible for injecting dependencies. Coupling : Encourages loose coupling by decoupling ob

Add Godaddy SSL Certificate to IIS 10 Server | Rekey

How to Add Godaddy SSL Certificate to IIS 10 (Full 2024 Guide)? Installing Godaddy SSL Certificate on IIS 10 Server? Rekey and Install SSL Certificate in IIS 10 Server? Manually Install an SSL Certificate on my IIS 10 Server? Download the SSL Certificate from GoDaddy: ·         Go to your GoDaddy account and navigate to the SSL Certificates section. ·         Find your issued SSL certificate and click Download. ·         Choose the correct server type from the dropdown and download the certificate files (usually a .crt file). Create the .pfx file using the below OpenSSL command prompt: openssl pkcs12 -export -out certificate.pfx -inkey generated-private-key.txt -in 530276e452e0d3fb.crt -certfile 530276e452e0d3fb.crt As per above command: ·         Downloaded the 'Generated Private Key' text file: generated-private-key.txt ·         Download CRT file:   530276e452e0d3fb.crt ·         New PFX file that will create in the folder with certificate name (as per y

Odd Even Numbers 1 to 10 program in c#

 Question on the Odd-Even Numbers 1 to 10 program in c# 1. Print all even numbers from 1 to 10  2. Print the sum of all odd numbers from 1 to 10 3. Print all numbers from 1 to 10 that are divisible by 3 Explanation: Even Numbers:  The program uses a  for  loop to iterate through numbers from 1 to 10. It checks if a number is even using  i % 2 == 0  and prints it if true. Sum of Odd Numbers:  The program calculates the sum of odd numbers by checking if a number is odd using  i % 2 != 0  and adding it to the  sumOfOdds   variable. Numbers Divisible by 3:  The program checks each number from 1 to 10 to see if it's divisible by 3 using  i % 3 == 0  and prints it if true. Example, class EvenOddNumber {     static void Main()     {         // 1. Print all even numbers from 1 to 10         Console.WriteLine("Even numbers from 1 to 10:");         for (int i = 1; i <= 10; i++)         {             if (i % 2 == 0)             {                 Console.WriteLine(i);            

Promises in JavaScript | Promises in JavaScript are a powerful way to handle asynchronous operations.

Promises in JavaScript are a powerful way to handle asynchronous operations. They represent a value that may be available now, or in the future, or never. Promises provide a cleaner and more intuitive way to work with asynchronous code compared to traditional callback-based approaches. Basics of Promises A Promise object represents an asynchronous operation's eventual completion (or failure) and its resulting value.  Promises can be in one of three states: Pending : The initial state. Neither fulfilled nor rejected. Fulfilled : The operation completed successfully. Rejected : The operation failed. Creating a Promise: You create a new Promise using the Promise constructor, which takes a function (called the executor function) that has two parameters: resolve and reject . //Promises in JavaScript - Promises in JavaScript are a powerful way to handle asynchronous operations. //Promises can be in one of three states: //Pending: The initial state. Neither fulfilled nor rejected. //

To count the number of vowel characters in a string using JavaScript

//To count the number of vowel characters in a string using JavaScript let message = 'Hello w0rld' ; let vowels = 'aeiou' let count = 0 //solution 1 for ( let chr of message ){     if ( vowels . includes ( chr )){     count = count + 1 ;    }   } console . log ( "Solution1: " + count ); //solution 2 function countVowels ( data ){   let count = 0 ;   data . split ( '' ). forEach ( x => {     if ( vowels . includes ( x )){         count = count + 1 ;     }   });   return count ; } let countVowel = countVowels ( message ); console . log ( "Solution2: " + countVowel );