Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- export interface User {
- id: number;
- login: string;
- password: string;
- }
- import { Injectable } from '@angular/core';
- import {HttpClient, HttpHeaders} from '@angular/common/http';
- import {Observable} from 'rxjs/Observable';
- import {User} from './interfaces/User';
- const httpOptions = {
- headers: new HttpHeaders({ 'Content-Type': 'application/json' })
- };
- @Injectable()
- export class UserService {
- constructor(private http: HttpClient) { }
- public addUser(newUser: User): Observable<{}> {
- return this.http.post('http://localhost:8080/users/newuser', newUser);
- }
- public extractData(res: Response) {
- const body = res.json();
- return body || {};
- }
- }
- import { Component, OnInit } from '@angular/core';
- import {UserService} from '../user.service';
- import {User} from '../interfaces/User';
- @Component({
- selector: 'app-register',
- templateUrl: './register.component.html',
- styleUrls: ['./register.component.scss']
- })
- export class RegisterComponent implements OnInit {
- users: User[];
- constructor(private userService: UserService) {
- }
- ngOnInit() {
- }
- addUser(emailText: string, passwordText: string) {
- const newUser: User = ({
- id: null,
- login: emailText,
- password: passwordText
- });
- this.userService.addUser(newUser);
- console.log(JSON.stringify(newUser));
- }
- }
Add Comment
Please, Sign In to add comment