Advertisement
roynaldoindra

apitransaksi-service.ts

Aug 12th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. import { Injectable } from '@angular/core';
  2. import { Http } from '@angular/http';
  3. import 'rxjs/add/operator/map';
  4.  
  5. /*
  6. Generated class for the RestapiService provider.
  7.  
  8. See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  9. for more info on providers and Angular 2 DI.
  10. */
  11. @Injectable()
  12. export class ApitransaksiService {
  13.  
  14. host : string = 'http://localhost/sss/index.php/ApiTransaksi';
  15. param : any;
  16. url : any;
  17.  
  18. constructor(public http: Http) {
  19. console.log('Hello RestapiService Provider');
  20. this.param = {};
  21. this.url = '';
  22. }
  23.  
  24. public getHost(){
  25. return this.host;
  26. }
  27.  
  28. public loadTransaksi(param){
  29. this.param = param;
  30. this.url = this.host;
  31. return this.getData();
  32. }
  33.  
  34.  
  35. public viewTransaksidetil(param){
  36. this.param = param;
  37. this.url = this.host +'/index/detail/id_pemesan/' + param.id_pemesan;
  38. return this.getData();
  39. }
  40.  
  41. /*public viewReservasi(param){
  42. this.param = param;
  43. this.url = this.host2 +'/index/id_user/' + param.id_user;
  44. return this.getDataReservasi();
  45. }*/
  46.  
  47. public transaksiList(param){
  48. this.param = param;
  49. this.url = this.host;
  50. return this.getData();
  51. }
  52.  
  53.  
  54. private getData() {
  55. let param = {
  56. data : this.param
  57. };
  58. return new Promise(resolve => {
  59. this.http.get(this.url,param).subscribe(data => {
  60. //let r = data.json();
  61. resolve(data.json());
  62. },
  63. err => {
  64. //let r : any = err;
  65. //let parse = JSON.parse(r._body);
  66. resolve(err.json());
  67. });
  68. });
  69. }
  70.  
  71. /*private getDataReservasi() {
  72. let param = {
  73. data : this.param
  74. };
  75. return new Promise(resolve => {
  76. this.http.get(this.url,param).subscribe(data => {
  77. //let r = data.json();
  78. resolve(data.json());
  79. },
  80. err => {
  81. //let r : any = err;
  82. //let parse = JSON.parse(r._body);
  83. resolve(err.json());
  84. });
  85. });
  86. }*/
  87.  
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement