31 encapsulates a network service request

① create a service class

  @Injectable()

  Service class defined in the method, the data

  sendRequest ( myUrl : string ) {

    return this.http.get( myUrl ).map(  (response : Response) => response.json()  )

  }

② to the designated service provider

  providers: [MyHttpService] module assembly defines a scope

③ call service

  import { }

  this.myHttpService.sendRequset ( 'address request') .subscribe ((result: any) => {console.log (reuslt)})

Guess you like

Origin www.cnblogs.com/shanlu0000/p/12230051.html