Advertisement
Guest User

Untitled

a guest
May 17th, 2018
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         <div class="CreateSettleParticipantBlock">
  2.           <h1>Participants</h1>
  3.  
  4.           <!!=*=.=>
  5.             <label for="name">Person {{ i + 1 }}</label>
  6.             <input type="text" class="form-control" id="participant{{i}}" name="participant{{i}}" ([ngModel])="participant.name">
  7.           </div>
  8.  
  9.           <button type="button" class="btn btn-info" (click)="addNewParticipant()">Add new person</button>
  10.         </div>
  11.  
  12. import {Component, OnInit} from '@angular/core';
  13. import {Settle} from "../settle";
  14. import {Participant} from "../participant";
  15. import {SettleService} from "../settle.service";
  16. import {Currency} from "../currency";
  17. import {Router} from "@angular/router";
  18. import {UUID} from 'angular2-uuid';
  19. import {AppConfig} from "../config/app.config";
  20.  
  21. @Component({
  22.   selector: 'app-create',
  23.   templateUrl: './create.component.html',
  24.   styleUrls: ['./create.component.css']
  25. })
  26.  
  27. export class CreateComponent implements OnInit {
  28.   submitted = false;
  29.   currencies = new Array<Currency>();
  30.   settles = new Array<Settle>();
  31.  
  32.   private frontEndpoint = AppConfig.endpoints.front;
  33.  
  34.   public model: Settle;
  35.  
  36.   constructor(private settleService: SettleService, private router: Router) {
  37.   }
  38.  
  39.   ngOnInit() {
  40.     this.getCurrencies();
  41.     this.getSettles();
  42.  
  43.     this.model = new Settle();
  44.     this.model.participants = [{ name: ''}];
  45.   }
  46.  
  47.   onSubmit() {
  48.     this.model.token = UUID.UUID();
  49.  
  50.     this.settleService
  51.       .addSettle(this.model)
  52.       .subscribe(settle => this.settles.push(settle));
  53.  
  54.     this.router.navigate([`${this.frontEndpoint}/settle/${this.model.token}`]);
  55.  
  56.     this.submitted = true;
  57.   }
  58.  
  59.   addNewParticipant(): void {
  60.     this.model.participants.push(new Participant(''));
  61.   }
  62.  
  63.   getCurrencies(): void {
  64.     this.settleService
  65.       .getCurrencies()
  66.       .subscribe(currencies => this.currencies = currencies);
  67.   }
  68.  
  69.   getSettles(): void {
  70.     this.settleService
  71.       .getSettles(1)
  72.       .subscribe(settles => this.settles = settles);
  73.   }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement