detectChanges
and markForCheck
? Scenario: @Input changed and component has not been refreshed.detectChanges
(), detach
(), markForCheck
() and others in your components. This can be a great solution if you need full control over change detection. For instance, if you're getting data from a websocket
you may want to use detectChanges
() to limit how often you're checking for changes. If you don't need full control, however, it can certainly over-complicate things.There's an Observable field in a component, it got subscribed to. Can you spot a memory leak? (it should be unsubscribed from inngOnDestroy
)
Subscription
as this.Subscription: represents the execution of an Observable, is primarily useful for cancelling the execution.
Observables
. The pattern seems to almost dictate that Subscriptions
are simply a “viewership” to the source and not something that controls the source. This is mostly because of the different types of Observables that we come to use and our inability to always know what type an observable is and what really happens when you do unsubscribe
from the Subscription
.subscribe
you are essentially just starting to listen. Similarly when you unsubscribe
you are stopping your listening. Following is a classic example of a hot observable.The observable is already working and streaming data. A realworld example might be when you enter in a life-stream movie, the movie is already streaming no matters if you are subscribed or not. Example,behaviorSubject
subscribe
. Similarly, the observer ends the underlying operation for that observer with an unsubscribe
. Most creation operators create a cold observable.The observable does not stream data to the subscriptor until such is subscribed. A realworld example might be if you visit Netflix and start a movie, the movie will be displayed when you "subscribe" to it.
behaviorsubject
works in angular?next()
onnext
getValue()
method.In addition, you can get an observable from behavior subject using theasObservable()
method onBehaviorSubject
.