Return to site

ANGULAR INTERVIEW QUESTION: How does subscribe() method works?

January 17, 2022

First, let's remind that an Observable publishes values only when we subscribe to it.

So to subscribe to such stream, you have to invoke its subscribe() method, and we parse to it an observer.

 

Usually we do not pass the observer but a command line:

 

It is a coding shortcut.

𝐒ðĻ, ð­ðĄðž 𝐎ðŪ𝐛𝐎𝐜ðŦðĒ𝐛𝐞 ðĶðžð­ðĄðĻ𝐝 ðĒ𝐎 𝐚 ðĶðžð­ðĄðĻ𝐝 ðĻ𝐟 𝐎𝐛𝐎𝐞ðŦðŊ𝐚𝐛ðĨ𝐞𝐎, ð°ðĄðĒðœðĄ 𝐭𝐚ðĪ𝐞𝐎 𝐚𝐧 𝐎𝐛𝐎𝐞ðŦðŊ𝐞ðŦ 𝐚𝐎 ðĐ𝐚ðŦ𝐚ðĶ 𝐚𝐧𝐝 𝐝𝐞𝐚ðĨ𝐎 𝐰ðĒð­ðĄ 𝐝ðĒ𝐟𝐟𝐞ðŦ𝐞𝐧𝐭 𝐧ðĻ𝐭ðĒ𝐟ðĒ𝐜𝐚𝐭ðĒðĻ𝐧𝐎 ðŦ𝐞𝐜𝐞ðĒðŊ𝐞𝐝 𝐛ðē ð­ðĄðž 𝐎𝐭ðŦ𝐞𝐚ðĶ.