What is the difference between an observable and a subject?
While plain Observables are unicast (each subscribed Observer owns an independent execution of the Observable), Subjects are multicast. A Subject is like an Observable, but can multicast to many Observers. Subjects are like EventEmitters: they maintain a registry of many listeners. Every Subject is an Observable.
Observable is a Generic, and BehaviorSubject is technically a sub-type of Observable because BehaviorSubject is an observable with specific qualities. An observable can be created from both Subject and BehaviorSubject using subject. asObservable() .
1. Specific: An observable action, behavior or achievement is described which is also linked to a rate, number, percentage or frequency. Measurable: A system, method or procedure exists which allows the tracking and recording of the behavior or action upon which the objective is focused.
Observable behaviors include whatever you can see another person doing. This includes walking, talking, sitting, singing, hugging, eating, sleeping, doing math problems, and the like. Unobservable behaviors include the mental and emotional activities and states that cannot be directly observed.
Observer : Any object that wishes to be notified when the state of another object changes. Observable : Any object whose state may be of interest, and in whom another object may register an interest.
Promises deal with one asynchronous event at a time, while observables handle a sequence of asynchronous events over a period of time. Emit multiple values over a period of time.
In Subject, the subscribers will only receive the upcoming value. In BehaviorSubject, the subscribers will receive the previous value and also upcoming value.
A BehaviorSubject holds one value (so we actually need to initialize a default value). When it is subscribed it emits that value immediately. A Subject on the other hand, does not hold a value.
The ReplaySubject stored an arbitrary number of events, the BehaviorSubject only records the value of the latest event. Whenever a BehaviorSubject records a new subscription, it emits the latest value to the subscriber as well as any new values that are passed in.
Observable behaviors (also known as overt behaviors) are actions performed by an organism that can be seen and measured. This is an important focus in behaviorism who place emphasis only on observable behaviors instead of cognitive mental processes which cannot be seen by the human eye.
Why is it important to describe a behavior in observable and measurable terms?
Sticking to describing the behavior in observable terms will help you avoid one of the most common problems with defining behaviors: subjective evaluations that list inferred characteristics (e.g., sad, happy, upset, mad) or covert behaviors (e.g., thinking, remembering).
Using observable and measurable terms to describe behaviors and intervention outcomes allow practitioners to accurately observe and record when behaviors do or do not occur, and therefore when procedures should be applied.

behaviorism. The school of psychology, founded by John Watson, that defines psychology as the scientific study of observable behavior.
The definition of behavior is the way a person or thing acts or reacts. A child throwing a tantrum is an example of bad behavior. The actions of chimps studied by scientists are an example of behaviors. noun. 2.
Examples of non-behavior include: being quiet, not eating candy and not responding. These examples are not behaviors because a dead man could do them and they are not readily observable.
Definition of observer
: one that observes: such as. a : a representative sent to observe but not participate officially in an activity (such as a meeting or war) b : an expert analyst and commentator in a particular field political observers.
Observable are just that — things you wish to observe and take action on. Angular uses the Observer pattern which simply means — Observable objects are registered, and other objects observe (in Angular using the subscribe method) them and take action when the observable object is acted on in some way.
Observables are not executed until a consumer subscribes. The subscribe() executes the defined behavior once, and it can be called again. Each subscription has its own computation. Resubscription causes recomputation of values.
Angular makes use of observables as an interface to handle a variety of common asynchronous operations. For example: The HTTP module uses observables to handle AJAX requests and responses. The Router and Forms modules use observables to listen for and respond to user-input events.
Callbacks are functions passed as arguments into other functions to make sure mandatory variables are available within the callback-function's scope. Promises are placeholder objects for data that's available in the future.
How do you handle observable errors?
Catch errors in the observable stream
Another option to catch errors is to use the CatchError Operator. The CatchError Operators catches the error in the observable stream as and when the error happens. This allows us to retry the failed observable or use a replacement observable.
A Subject is a special type of Observable that allows values to be multicasted to many Observers. The subjects are also observers because they can subscribe to another observable and get value from it, which it will multicast to all of its subscribers. Basically, a subject can act as both observable & an observer.
...
Cheat sheetlink.
Operation | Observable | Promise |
---|---|---|
Subscribe | sub = obs.subscribe((value) => { console.log(value) }); | promise.then((value) => { console.log(value); }); |
In Subject, the subscribers will only receive the upcoming value. In BehaviorSubject, the subscribers will receive the previous value and also upcoming value.
Observable are just that — things you wish to observe and take action on. Angular uses the Observer pattern which simply means — Observable objects are registered, and other objects observe (in Angular using the subscribe method) them and take action when the observable object is acted on in some way.