Angular · Middle · Question 72 of 75

Why avoid subscribe inside a component just to copy values into fields?

ngOnInit() {
  this.service.users$.subscribe((u) => (this.users = u));
}

Explanation

Declarative bindings tie the subscription to the view's lifetime and notify change detection automatically.

Further reading

Problem with a question

Angular · Middle · question 72

Test yourself

Take the Angular · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz