0

I have a component and I have implemented OnInit, OnChanges interfaces

OnInit and OnChanges are imported from '@angular/core' at the top of file.

like below

 import { Component, OnInit, Output, EventEmitter, Input, OnChanges } from '@angular/core';

But when I try to implement OnChanges interfaces using Visual Studio shortcut like below

enter image description here

It had added method like below

enter image description here

So I couldnt understand the diffrence between below cases:

case 1: importing SimpleChanges at top of file

import { SimpleChanges } from '@angular/core';

Case 2: importing SimpleChanges in function parameter

 ngOnChanges(changes: import("@angular/core").SimpleChanges): void {
    throw new Error("Method not implemented.");
  }

1 Answer 1

2

The difference: importing SimpleChanges at top of file makes it visible for all code in the file. Importing as function argument makes it visible only for function. Visual studio code generator goes on the way of minimal impact and side effects of generated code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.