Deepak Verma
What does a Subscribe method do in Angular 4?
By Deepak Verma in Angular on Jun 19 2018
  • Shivam Shukla
    Jun, 2018 27

    First of all, .subscribe is not an Angular2 thing. That's a method that comes from rxjs library which Angular is using behind the scene. If you can imagine yourself when subscribing to a newsletter and after the subscribing, every time that there is a new newsletter, they will send it to your home ( the method inside subscribe get's called). That's what happens when you subscribing to a source of magazines ( which they call it Observable in rxjs library) All the AJAX calls in Angular is using this library behind the scene and in order to use any of them, you've got to use the method name, e.g get, and then call subscribe on it, because get returns and Observable. Also, when you're doing this

  • Bhairab Dutt
    Jun, 2018 26

    Hi Deepak,In Angular we are using subscribe within component for getting the data from API through angular service as below :this.testService.get('yourl') {.subscribe(async testmodel => {this.testmodel = await testmodel } error => console.log('If error', error));As you can see above I am calling the service and getting the data asynchronously using subscribe.Hope Its help you.

    • 1

Most Popular Job Functions