HttpService in Angular Framework:-

It is used to handle HttpRequest from external resources and fetch data from external resources .we will create web API or web services to get data from a remote server,web services, and web API will be called by HttpService in Angular Framework.


Web Services will be created by Server side script such as Java,PHP,.NET, PYTHON, Ruby, etc, and Consumed by Angular HTTP Service.


in Angular (currently on Angular-6) .subscribe() is a method on the Observable type. The Observable type is a utility that asynchronously or synchronously streams data to a variety of components or services that have subscribed to the observable.

import { Component, OnInit } from '@angular/core';
import { MyserviceService } from '../myservice.service';
@Component({
  selector: 'app-home',
  templateUrl: './home.component.html',
  styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
  s;
  public persondata = [];
  constructor(private myser: MyserviceService) {
   this.s= this.myser.show()
   }

  ngOnInit() {
  this.myser.getData().subscribe((data) => {
         this.persondata = Array.from(Object.keys(data), k=>data[k]);
         
      });
  }


}


<h3>Users Data</h3>
<ul>
   <li *ngFor="let item of persondata;">
      {{item.name}}
   </li>
</ul>

                                        

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post