Advertisement
ayami123

SignUpService

Jan 10th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { HttpClient } from '@angular/common/http';
  2. import { Injectable } from '@angular/core';
  3. import { Http, Headers} from '@angular/http';
  4. import 'rxjs/add/operator/map';
  5. import { SignUpContainer } from '../../pages/signup/signup.model';
  6. import { reject } from 'q';
  7.  
  8. /*
  9.   Generated class for the SignUpServiceProvider provider.
  10.  
  11.   See https://angular.io/guide/dependency-injection for more info on providers
  12.   and Angular DI.
  13. */
  14. @Injectable()
  15. export class SignUpServiceProvider {
  16.  url:string = "http://localhost:3800";
  17.  data: any;
  18.  
  19.   constructor(public $http: Http) {
  20.     console.log('Hello SignUpServiceProvider Provider');
  21.     this.data = [
  22.       {name:'Microsoft', code: 324, product: 'Windows 10'},
  23.       {name:'Microsoft', code: 678, product: 'Windows 7'}
  24.     ];
  25.   }
  26.  
  27.   loadAll(){
  28.     return Promise.resolve(this.data);
  29.   }
  30.  
  31.     postData(registerContainer: SignUpContainer) {
  32.     return new Promise((resolve, reject) => {
  33.       this.$http.post(this.url + "/api/users/add",
  34.       {
  35.         "username": registerContainer.username,
  36.         "password": registerContainer.password,
  37.         "email": registerContainer.email,
  38.         "name": registerContainer.name,
  39.       }).subscribe(res => {
  40.           resolve(res.json());
  41.           console.log(res.json);
  42.         }, (err) => {
  43.           reject(err);
  44.         });
  45.     });
  46. }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement