7

We had $scope.$apply() in angularjs that perform proper scope life cycle of angularjs.

Is there any equivalent to this in Angular 6?

2 Answers 2

15

You are looking for ChangeDetectorRef

Inject within your constructor

constructor(private ref: ChangeDetectorRef) {
}

and call

this.ref.detectChanges();
Sign up to request clarification or add additional context in comments.

Comments

5

You can inject ChangeDetectorRef and use it for manually running change detection. It has methods that run change detection or stop it for that component. You can explore methods of ChangeDetectorRef looking above link.

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

@Component({
   ...
})
export class MyComponent {

   constructor(private changeDetector: ChangeDetectorRef ) {

   }

}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.