2

All the best,

Well, my problem is when implementing the events (OnChanges, DoCheck) in my component and it's fine, but when executing the "ng lint" command I get an error that these events are not well declared or implemented, so I have structured the events in my component but I get an error, so my question is if I'm doing something wrong or is there another way to implement them:

ERROR:

18:43  error  Implementing DoCheck and OnChanges in a class is not recommended          @angular-eslint/no-conflicting-lifecycle
18:52  error  Implementing DoCheck and OnChanges in a class is not recommended          @angular-eslint/no-conflicting-lifecycle
68:3   error  Declaring ngDoCheck and ngOnChanges method in a class is not recommended  @angular-eslint/no-conflicting-lifecycle
125:3   error  Declaring ngDoCheck and ngOnChanges method in a class is not recommended  @angular-eslint/no-conflicting-lifecycle

CODIGO:

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

export class DualListComponent implements DoCheck, OnChanges {
    ...
}

ngOnChanges(changeRecord: { [key: string]: SimpleChange }): void {
    ...
}

ngDoCheck(): void {  
    ...
}
0

1 Answer 1

1

When the default change detector detects changes, it invokes ngOnChanges() if supplied, regardless of whether you perform additional change detection. Typically, you should not use both DoCheck and OnChanges to respond to changes on the same input.

https://angular.io/api/core/DoCheck#usage-notes

It is just enforcing the recommendation from Angular not to implement these together in the same component.

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

1 Comment

Investigating the documentation that you have recommended and the tests that I have carried out, these 2 events should not be implemented together, so I have to use one of the 2 and not both at the same time. Thanks.

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.