Angular 9 Tutorial For Beginners #54 - Observable 1. Observable is part of RxJs library 2. import observable into our component where we want to make use of it 3. Observable is a sequence of data that is emitted over period of time 4. This data can be of any time - string , events, etc 5. Angular uses observable very frequently in most aysnc operations - HTTP, Routing, Event Handling 6. In order to listen and track the changes of observable - we need observer 7. The observer will continuously track the changes in observable 8. Observer has methods like - next (), error (), complete() 9. Observable as it - is useless unless we subscribe it 10. By subscribe we mean that we are processing the data/values by observable over period of time 11. We can have multiple subscribers to our observable 12. We can also unsubscribe from a subscriber Example: Shopping Cart - Initial Order - InProgress - Processing - Trasit - Delivered - Completed component.ts import { Component, OnInit } from '@angular/core'; import { Observable, Subscriber } from 'rxjs'; @Component({ selector: 'app-observable', templateUrl: './observable.component.html', styleUrls: ['./observable.component.scss'] }) export class ObservableComponent implements OnInit { orderStatus: any; data: Observable; constructor() { } ngOnInit(): void { this.data = new Observable(o => { //Business Logic comes here setTimeout(() => { o.next('In Progress'); }, 4000); //Business Logic comes here setTimeout(() => { o.next('Processing'); }, 8000); //Business Logic comes here setTimeout(() => { o.next('Trasit'); }, 12000); //Business Logic comes here setTimeout(() => { o.next('Delivered'); }, 16000); //Business Logic comes here setTimeout(() => { o.next('Completed'); }, 20000); // //if any error setTimeout(() => { o.error(); }, 8000); // It will no more track or listen the changes. setTimeout(() => { o.complete(); }, 10000); setTimeout(() => { o.next('Msg after Completed executed'); }, 20000); }); //first subscription this.data.subscribe(o => { this.orderStatus = o; }); //second subscription -> val2 // this.data.subscribe(val2 => { this.orderStatus = val2; }); } } component.html Order Status - {{orderStatus}}
Thank you so much sir for each great video. I wish I could work for you someday to spend time in such a great Team of yours and I am proud of you saying, my Teacher :)
Sir you are awesome! Please make a complete tutorial about angular inside one course. Like building a todos or a shopping cart, going through all angular stuff in it. 🙏 may God bless you
Hi Adam. I have already create 1 Angular e-commerce module project. I have create more in coming days. Please check this playlist. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-I5i1GonlfFM.html
Thanks and welcome. Thank you for your support. Do check out the Angular 10 series as well ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Fg4spR6cdBQ.html
Hi Sai. Please follow Angular 10 tutorial series as this will be covered again in detail and you can practice with me along. Please check Angular 10 tutorial series for complete learning ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-oEO0KzY1ipg.html
Hi.. Where is that app, which folders are there.. cart and product and all components.. Login and all.. I want to learn to build whole app.. So If you have made any such videos, then please share me a link
Hi, I have doubts regarding observables. Actually, we can write API calls(one after another one) without using observables. but why we need to use observables, what is the use of observables?
Hi Siva. We use observables so that we can get latest data that is emitted or listen to any changes that has happened. I will cover it this topic again in Angular 10 series. Stay tuned for that
Sir, what are the languages should I need to learn to become backend developer? Because, I almost completed front-end development. So I think it's better to move on back-end side. Please tell me sir what are skills required to become back-end development.
Hi Shanti. For backend if you are focusing on MEAN stack - you should learn Node, Express and of course JavaScript. I have created tutorials for Node and Express. Please check them out
this is showing error in Angular 11 data : Observable; ERROR- Property 'data' has no initializer and is not definitely assigned in the constructor. so what is the alternative for this, if you can please guide.
Hi Sridhar, I am a beginner in Angular. When I install Angular/cli, I do not see the e2e folder. Do you have any idea why is that happening. Is e2e important for my application?
Hi Vivek. Please follow Angular 10 tutorial series as this will be covered again in detail and you can practice with me along. Please check Angular 10 tutorial series for complete learning ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-oEO0KzY1ipg.html
Sure Mayur. I will create soon. In the meanwhile please follow along in Angular 10 series, I will soon start a live project ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Fg4spR6cdBQ.html
HI thanks for the tutorial its very usefull for me. but i have one question: this.datos.subscribe(val => { this.order = val; console.log('VAL: ' + this.order); }); in this part of the code the log method is not working for me.! why?
Hi Jhon. The most certain reason will be due tinthe difference in data type of this.order. U need to create a model and then declare this.order of the same data type as is returned in val. Try this fix out!!!
@@ARCTutorials HI, let me explain better. I declare order as any. order: any; in the html i have this: ORDER: {{order}} I work fine, but... if i want to show it in console doesnt work! console.log('VAL: ' + this.order); in you video you put some console.log() but you never show you console to see it ;-) PD: anyway this tutorial help me to solve my problem in my app with asynchronous functions running parallel. THANKS YOU VERY MUCH!
Why cant i get data.next() and data.complete methods ? is data is not an observer here? this.authservice.registerform(form).subscribe(data => { data.? (not working for complete and next) this.ifsuccess = true; this.timer = setInterval(() => { this.router.navigate(['']); }, 1200); }); registerform(data): Observable{ return this.httpclient.post('localhost:3000/login',data); } Please help ! Your videos helped me a lot to improve in angular as a beginner, Thanks to you
Hi Mayur. Can you pls start following Angular 10 series. I have recently started the http tutorial. It will surely help you. ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-U71G375Aw6E.html
Hi Siva. I am releasing one more video today on Observables, Subscribe and more today as part of Angular 10 series. Please subscribe so you will get notification.