Changeset 6c1585f for trip-planner-front/src/app/planner/edit-planner
- Timestamp:
- 11/04/21 23:10:39 (3 years ago)
- Branches:
- master
- Children:
- ceaed42
- Parents:
- 6a80231
- Location:
- trip-planner-front/src/app/planner/edit-planner
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.html
r6a80231 r6c1585f 3 3 <h3>Here you can edit your planner</h3> 4 4 5 <form >5 <form [formGroup] = "form" (ngSubmit)="onSubmit()"> 6 6 <div class="form-gorup"> 7 7 <p>Planner name</p> 8 8 <mat-form-field appearance="fill"> 9 <input matInput required type="text" name="name" placeholder="Planner name">9 <input matInput required type="text" formControlName="name" placeholder="Planner name"> 10 10 </mat-form-field> 11 11 <p>Planner description</p> 12 12 <mat-form-field appearance="fill"> 13 <textarea matInput required name="description" type="text" placeholder="Planner description"></textarea>13 <textarea matInput required formControlName="description" type="text" placeholder="Planner description"></textarea> 14 14 </mat-form-field> 15 15 </div> … … 25 25 </thead> 26 26 <tbody> 27 <tr> 28 27 <tr> 29 28 <td> <button mat-raised-button color="primary" (click)="onClickAddLocation()"> 30 29 Add locations … … 38 37 </div> 39 38 </div> 40 <button mat-raised-button color="primary" (click)="onClickSavePlanner()">39 <button mat-raised-button color="primary" > 41 40 <mat-icon>edit</mat-icon> Save 42 41 </button> -
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts
r6a80231 r6c1585f 1 1 import { Component, OnInit } from '@angular/core'; 2 import { Router } from '@angular/router'; 2 import { FormBuilder, FormGroup, Validators } from '@angular/forms'; 3 import { ActivatedRoute, Router } from '@angular/router'; 4 import { PlannerDto } from 'src/app/_models/dto/plannerDto'; 3 5 import { Planner } from 'src/app/_models/planner'; 6 import { PlannerService } from 'src/app/_services/planner.service'; 4 7 5 8 @Component({ … … 11 14 12 15 planner: Planner; 16 planners: Planner[]; 17 form: FormGroup; 18 plannerDto: PlannerDto; 19 id: number; 13 20 14 21 15 constructor(private router: Router ) {22 constructor(private router: Router, private route: ActivatedRoute ,private fb: FormBuilder, private plannerService: PlannerService) { 16 23 this.planner = new Planner(); 24 this.planners = []; 25 this.form = fb.group({ 26 title: fb.control('initial value', Validators.required) 27 }); 28 this.plannerDto = new PlannerDto(); 29 this.id = 1; 17 30 } 18 31 19 32 ngOnInit(): void { 33 this.id = this.route.snapshot.params['id']; 34 35 this.form = this.fb.group({ 36 name: [''], 37 description: [''], 38 locationList: [] 39 }); 40 41 this.plannerService.getPlannerById(this.id) 42 .pipe() 43 .subscribe(x => this.form.patchValue(x)); 20 44 } 21 45 22 46 23 onClickSavePlanner(){ 24 this.router.navigate(['planners']); 47 onSubmit(){ 48 this.updatePlanner(); 49 25 50 } 26 51 27 onClickAddLocation(){ 52 onClickAddLocation() 53 { 28 54 this.router.navigate(['form']); 29 55 } 56 57 private updatePlanner() { 58 this.plannerService.updatePlanner(this.id, this.form.value) 59 .pipe() 60 .subscribe({ 61 next: () => { 62 this.router.navigate(['planners']); 63 }, 64 error: error => { 65 console.log("error"); 66 } 67 }); 30 68 } 69 70 }
Note:
See TracChangeset
for help on using the changeset viewer.