Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- formats:
- {
- "/api": {
- "target": "http://localhost:1100",
- "secure": false,
- }
- }
- "scripts": {
- "ng": "ng",
- "start": "ng serve --proxy-config proxy.config.json",
- "build": "ng build",
- "test": "ng test",
- "lint": "ng lint",
- "e2e": "ng e2e"
- },
- import { Injectable } from '@angular/core';
- import { HttpHeaders, HttpClient, HttpParams } from '@angular/common/http';
- import { Observable } from 'rxjs/Observable';
- import { ErrorObservable } from 'rxjs/observable/ErrorObservable';
- import { catchError } from 'rxjs/operators/catchError';
- @Injectable({
- providedIn: 'root'
- })
- export class ApiService {
- private apiUrl: string;
- constructor(
- private http: HttpClient,
- ) {
- this.apiUrl = '';
- }
- private formatErrors(error: any) {
- console.log(error)
- return new ErrorObservable(error);
- }
- get(path: string, params: HttpParams = new HttpParams()): Observable<any> {
- return this.http.get(`${this.apiUrl}${path}`, { params })
- .pipe(catchError(this.formatErrors));
- }
- post(path: string, body: Object = {}): Observable<any> {
- return this.http.post(
- `${this.apiUrl}${path}`,
- JSON.stringify(body)
- ).pipe(catchError(this.formatErrors));
- }
- }
- import { Injectable } from '@angular/core';
- import { Observable } from 'rxjs/Observable';
- import { ApiService } from './api.service';
- import { map } from 'rxjs/operators/map';
- import {User} from '../models/user.model';
- @Injectable({
- providedIn: 'root'
- })
- export class UserService {
- constructor(private apiService: ApiService) { }
- signin(id, data): Observable<User>{
- return this.apiService.post('/api/user/signin', data)
- .pipe(map(data => data));
- }
- signup(id, data): Observable<User>{
- return this.apiService.post('/api/user/'+id+'/signup', data)
- .pipe(map(data => data));
- }
- }
- export class User{
- constructor(){};
- id: number;
- email: string;
- password:string ;
- firstName:string ;
- lastName:string ;
- type:number ;
- company:string;
- }
- import { Component, OnInit } from '@angular/core';
- import{User} from '../../core/models/user.model'
- import { UserService } from 'src/app/core';
- import { FormsModule, ReactiveFormsModule } from '@angular/forms';
- import { NgModule } from '@angular/core';
- @Component({
- selector: 'app-signin',
- templateUrl: './signin.component.html',
- styleUrls: ['./signin.component.css'],
- providers: [UserService],
- })
- @NgModule({
- imports: [
- FormsModule,
- ReactiveFormsModule,
- ],
- })
- export class SigninComponent implements OnInit {
- private user: User=new User();
- constructor(private userSvc: UserService) {
- this.user.email="";
- this.user.password="";
- }
- private email:string="";
- ngOnInit() {
- }
- ValidateLogin (){
- //validate
- var userid=0;
- alert(this.email);
- var param={firstName:this.user.firstName,
- lastName:this.user.lastName,
- email:this.user.email,
- password:this.user.password,
- company:this.user.company,
- type:1,
- };
- this.userSvc.signin(userid, this.user).subscribe(data => {
- if(Number(data.id)>0){
- console.log("return status: ");
- }
- else{ console.log("error");}
- });
- }
- }
- -----------------------------------------------------------
- @angular-devkit/architect 0.6.8
- @angular-devkit/build-angular 0.6.8
- @angular-devkit/build-optimizer 0.6.8
- @angular-devkit/core 0.6.8
- @angular-devkit/schematics 0.6.8
- @angular/cli 6.0.8
- @ngtools/webpack 6.0.8
- @schematics/angular 0.6.8
- @schematics/update 0.6.8
- rxjs 6.2.1
- typescript 2.7.2
- webpack 4.8.3
Add Comment
Please, Sign In to add comment