The observable pattern that allows an object, called the subject, to keep track of other objects, called observers, is interested in the subject state. When the subject state changes, it notifies its observers. The mechanism behind this is really simple.
Let's take a look at the following observer/subject implementation in pure TypeScript (no Angular 2 or framework of any kind, just Typescript). First, I defined an Observer interface that any concrete implementation will have to implement:
export interface Observer{
notify();
}
This interface only defines the notify() method. This method will be called by the subject (the object being observed by the observer) when its state changes. Then, I have an implementation of this interface, named HumanObserver:
export class HumanObserver implements Observer{ constructor(private name:string){}
notify(){
...