Changeset ceaed42 for trip-planner-front/src/app/planner
- Timestamp:
- 11/11/21 12:59:26 (3 years ago)
- Branches:
- master
- Children:
- 59329aa
- Parents:
- 6c1585f
- Location:
- trip-planner-front/src/app/planner
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.html
r6c1585f rceaed42 28 28 <td> <button mat-raised-button color="primary" (click)="onClickAddLocation()"> 29 29 Add locations 30 </button> 30 </button> 31 </td> 32 </tr> 33 <tr *ngFor ="let location of locations"> 34 <td> 35 {{location.name}} 31 36 </td> 32 37 </tr> -
trip-planner-front/src/app/planner/edit-planner/edit-planner.component.ts
r6c1585f rceaed42 3 3 import { ActivatedRoute, Router } from '@angular/router'; 4 4 import { PlannerDto } from 'src/app/_models/dto/plannerDto'; 5 import { Location } from 'src/app/_models/location'; 5 6 import { Planner } from 'src/app/_models/planner'; 7 import { LocationService } from 'src/app/_services/location.service'; 6 8 import { PlannerService } from 'src/app/_services/planner.service'; 7 9 … … 18 20 plannerDto: PlannerDto; 19 21 id: number; 22 locations: Location[]; 20 23 21 24 22 constructor(private router: Router, private route: ActivatedRoute ,private fb: FormBuilder, private plannerService: PlannerService) { 25 constructor(private router: Router, private route: ActivatedRoute, private fb: FormBuilder, private plannerService: PlannerService, 26 private locationService : LocationService) { 23 27 this.planner = new Planner(); 24 28 this.planners = []; 25 29 this.form = fb.group({ 26 30 title: fb.control('initial value', Validators.required) 27 });31 }); 28 32 this.plannerDto = new PlannerDto(); 29 33 this.id = 1; 34 this.locations = []; 30 35 } 31 36 … … 34 39 35 40 this.form = this.fb.group({ 36 37 38 41 name: [''], 42 description: [''], 43 locationList: [] 39 44 }); 40 45 41 46 this.plannerService.getPlannerById(this.id) 42 .pipe() 43 .subscribe(x => this.form.patchValue(x)); 47 .pipe() 48 .subscribe(x => this.form.patchValue(x)); 49 50 this.locationService.getLocationsFroPlanner(this.id).subscribe( 51 data => { 52 this.locations = data; 53 } 54 ); 55 } 56 57 onSubmit() { 58 this.updatePlanner(); 59 44 60 } 45 61 46 47 onSubmit(){ 48 this.updatePlanner(); 49 50 } 51 52 onClickAddLocation() 53 { 62 onClickAddLocation() { 54 63 this.router.navigate(['form']); 55 64 } … … 57 66 private updatePlanner() { 58 67 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 }); 68 .pipe() 69 .subscribe({ 70 next: () => { 71 this.router.navigate(['planners']); 72 }, 73 error: error => { 74 console.log("error"); 75 } 76 }); 77 } 78 68 79 } 69 70 } -
trip-planner-front/src/app/planner/planner.component.ts
r6c1585f rceaed42 22 22 23 23 24 constructor(private plannerService: PlannerService, p ublicdialog: MatDialog, private router: Router,24 constructor(private plannerService: PlannerService, private dialog: MatDialog, private router: Router, 25 25 private fb : FormBuilder) { 26 26 this.planners = []; … … 49 49 console.log(id); 50 50 this.plannerService.getPlannerById(id).subscribe( 51 data => { 52 53 this.router.navigate(['edit/planner/', id]) 51 data => { 52 this.router.navigate(['edit/planner/', id]); 54 53 } 55 54 );
Note:
See TracChangeset
for help on using the changeset viewer.