Advertisement
Guest User

Untitled

a guest
May 29th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Component, OnInit } from '@angular/core';
  2. import { SwiperComponent, SwiperDirective, SwiperConfigInterface,
  3.       SwiperScrollbarInterface, SwiperPaginationInterface } from 'ngx-swiper-wrapper';
  4. import { SliderComponent, UserNavComponent } from '../../components/index';
  5. import { User } from '../../_models/index';
  6. import { FormGroup, FormBuilder, Validators } from '@angular/forms';
  7. import { UserService, AuthenticationService } from '../../services/index';
  8.  
  9. @Component({
  10.     moduleId: module.id.toString(),
  11.     selector: 'app-user-dashboard',
  12.     templateUrl: './userdashboard.component.html',
  13.     styleUrls: ['userdashboard.component.css'],
  14. })
  15.  
  16. // tslint:disable-next-line:component-class-suffix
  17. export class UserDashboard implements OnInit {
  18.  
  19.   currentUser: User;
  20.     users: User[] = [];
  21.     model: any = {};
  22.     userDetails: any = {};
  23.     userUpdate: FormGroup;
  24.  
  25.   constructor(private userService: UserService, private auth: AuthenticationService, private fb: FormBuilder) {
  26.  
  27.         this.currentUser = JSON.parse(localStorage.getItem('currentUser'));
  28.         let test = this.auth.getUserDetails(this.currentUser.id);
  29.         test.subscribe(res => {
  30.           if (res && res.hasOwnProperty('Users') {
  31.             this.userDetails = res.Users[0];
  32.           }
  33.      });
  34.  
  35.     }
  36.  
  37.     ngOnInit() {
  38.         this.loadAllUsers();
  39.     }
  40.  
  41.     deleteUser(id: number) {
  42.       this.userService.delete(id).subscribe(() => { this.loadAllUsers();
  43.           });
  44.   }
  45.  private userUpdate(){
  46.     this.auth.update(this.model.username, this.model.password,
  47.               this.model.email, this.model.firstName, this.model.lastName,
  48.               this.model.ageMonth, this.model.ageDay, this.model.ageYear).subscribe(
  49.                   data => {
  50.                       this.alertService.success('Update successful', true);
  51.                      
  52.                   },
  53.        
  54.     }
  55.  
  56.   private loadAllUsers() {
  57.       this.userService.getAll().subscribe(users => { this.users = users; });
  58.   }
  59.  
  60.  
  61.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement