3 Explain components, modules and services in Angular.
Components, modules and services are the three fundamental building blocks in Angular. Components are the smallest, self-contained units in an Angular application. They are typically used to represent a view or UI element, such as a button or a form input field.Â
Code example:
import { Component, OnInit } from @angular/core;
     @Component({
       selector: app-test,
       templateUrl: ./test.component.html,
       styleUrls: [./test.component.css]
     })
     export lass TestComponent implements OnInit {
       constructor() {}
       ngOnInit() {
       }
     } Â
Modules are larger units that group together one or more related components. Services are singleton objects that provide specific functionality throughout an Angular application, such as data access or logging.
Code example:
import { BrowserModule } from @angular/platform-browser;
      import { NgModule } from @angular/core;
      import { AppComponent } from ./app.component;
      import { TestComponent } from ./test/text.component;
      @NgModule({
        declarations: [
          AppComponent,
          TestComponent
        ],
        imports: [
          BrowserModule
        ],
        providers: [],
        bootstrap: [AppComponent]
      })
      export class AppModule { }   Â
Each component in Angular has its own isolated scope. This means that a components dependencies (services, other components, etc.) are not accessible to any other component outside of its own scope. This isolation is important for ensuring modularity and flexibility in an Angular application.
Services, on the other hand, are not isolated and can be injected into any other unit in an Angular application (component, module, service, etc.). This makes them ideal for sharing data or functionality across the entire app.
Code example:
import { Injectable } from @angular/core;
      @Injectable({
        providedIn: root
      })
      export class TestServiceService {
        constructor() { }
      }
When designing an Angular application, it is important to keep these three building blocks in mind. Components should be small and self-contained, modules should group together related components, and services should provide shared functionality across the entire app. By following this design principle, you can create an Angular application that is modular, flexible, and easy to maintain.
What are the new updates with Angular10?Â
NGCC Feature – Addition of NGCC features with a program based entry point finder.Â
3 How do you perform Error handling?
In Angular, error handling can be done by writing a function using HttpClient along with catchError from RxJS.To handle errors, Angular’s HttpClient parses JSON responses and returns a JavaScript object in the observable.