Angular Interview Questions and Answers

2. What is Angular Universal? Explain its purpose.



3. Differentiate between ngOnChanges() and ngOnInit().

Example:


import { Component, OnChanges, SimpleChanges } from '@angular/core';

@Component({

  selector: 'app-example',

  template: '...'

})


export class ExampleComponent implements OnChanges {


  ngOnChanges(changes: SimpleChanges): void {


    // Perform actions based on changes to input properties


    if (changes.inputProperty) {


      // Handle changes to inputProperty


    }

  }

}

Example:

import { Component, OnInit } from '@angular/core';

@Component({

  selector: 'app-example',

  template: '...'

})

export class ExampleComponent implements OnInit {

  

ngOnInit(): void {


    // Perform initialization tasks


    // Fetch initial data, set up component state, etc.


  }

}


    }