Skip to content

Change Detection is broken #2452

@crtl

Description

@crtl

Version info

Angular:
9.1.4

Firebase:
7.14.2

AngularFire:
6.0.0

I have a UsersService which fetches users over https callable functions.
Subscribing to the observable returned breaks the change detection in my component.

Changing the changeDetection to ChangeDetectionStrategy.OnPush and explicitly calling ChangeDetectorRef.markForCheck() and ApplicationRef.tick() or running the subscribe block in an NgZone fixes the problem.

Steps to set up and reproduce

class MyService {
  constructor(protected firebaseFunctions: AngularFireFunctions) {}

  fetch() {
    const f = this.firebaseFunctions.httpsCallable("myFunc");
    return f({});
  }
}
class MyComponent implements OnInit {
  res: any;

  constructor(private service: MyService, private zone: NgZone) {}

  ngOnInit() {
    this.service.fetch().subscribe((res) => {
      this.res = res;
 
      // This works:
      // this.zone.run(() => {
      //   this.res = res;
      // });
    });

   
  }

}

Expected behavior

Shouldnt break change detection or explicitly state how to work around it in docs.

Actual behavior

Does not work.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions