import { Injectable } from '@angular/core';
import {HttpClient} from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class RegisterService {
url = 'http://unfaithfuldate.com/user/api';
constructor(private http : HttpClient) { }
sendForm(data){
return this.http.post(this.url,data).subscribe(data=>data);
}
}
import { Component, OnInit } from '@angular/core';
import {FormControl, FormGroup} from '@angular/forms';
import {RegisterService} from '../services/register.service';
@Component({
selector: 'app-auth-reg',
templateUrl: './auth-reg.component.html',
styleUrls: ['./auth-reg.component.css']
})
export class AuthRegComponent implements OnInit {
regForm = new FormGroup({
username : new FormControl(''),
email : new FormControl(''),
password : new FormControl(''),
gender : new FormControl('')
});
response : any;
constructor(private _registerService:RegisterService) {
}
ngOnInit() {
}
onRegister(){
this.response = this._registerService.sendForm(this.regForm.value);
console.log(this.response);
}
}
console.log– arturovt May 17 '19 at 13:57