Ignore:
Timestamp:
11/02/21 22:14:57 (3 years ago)
Author:
Ema <ema_spirova@…>
Branches:
master
Children:
6c1585f
Parents:
188ee53
Message:

create initial planner and routing with angular

Location:
trip-planner-front/src/app/create-initial-planner
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.html

    r188ee53 r6a80231  
    1 <h1 mat-dialog-title>Hi </h1>
    2 <div mat-dialog-content>
    3   <p>Trip name</p>
    4   <mat-form-field appearance="fill">
    5     <input matInput required >
    6   </mat-form-field>
    7   <p>Trip description</p>
    8   <mat-form-field appearance="fill">
    9     <textarea matInput ></textarea>
    10   </mat-form-field>
    11 </div>
    12 <div mat-dialog-actions>
    13   <button mat-button (click)="onCancelClick()">Cancel</button>
    14   <button mat-button cdkFocusInitial>Save</button>
    15 </div>
     1<form (ngSubmit)="onFormSubmitPlanner(f)" #f="ngForm">
     2  <h1 mat-dialog-title>Hi </h1>
     3  <div mat-dialog-content>
     4    <p>Planner name</p>
     5    <mat-form-field appearance="fill">
     6      <input matInput required   type="text" [(ngModel)]="plannerDto.name" name="name" placeholder="Planner name">
     7    </mat-form-field>
     8    <p>Planner description</p>
     9    <mat-form-field appearance="fill">
     10      <textarea matInput required name="description" [(ngModel)]="plannerDto.description" type="text" placeholder="Planner description"></textarea>
     11    </mat-form-field>
     12  </div>
     13  <div mat-dialog-actions>
     14   
     15    <button mat-button type="submit" [disabled]="!f.form.valid" >Save</button>
     16  </div>
     17</form>
     18
     19<button mat-button (click)="onCancelClick()">Cancel</button>
  • trip-planner-front/src/app/create-initial-planner/create-initial-planner.component.ts

    r188ee53 r6a80231  
     1import { ResourceLoader } from '@angular/compiler';
     2import { Route } from '@angular/compiler/src/core';
    13import { Component, Inject, OnInit } from '@angular/core';
     4import { NgForm } from '@angular/forms';
    25import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog';
     6import { ActivatedRoute, Params, Router } from '@angular/router';
     7import { PlannerDto } from '../_models/dto/plannerDto';
     8import { Planner } from '../_models/planner';
     9import { PlannerService } from '../_services/planner.service';
    310
    411@Component({
     
    916export class CreateInitialPlannerComponent implements OnInit {
    1017
    11   constructor(
    12     public dialogRef: MatDialogRef<CreateInitialPlannerComponent>) {}
     18  planner: Planner;
     19  planners: Planner[];
     20  locations : Location[];
     21  plannerDto: PlannerDto;
     22
     23  constructor(public dialogRef: MatDialogRef<CreateInitialPlannerComponent>,
     24              private plannerService : PlannerService, private router : Router) {
     25                this.planner = new Planner;
     26                this.planners = [];
     27                this.locations = [];
     28                this.plannerDto = new PlannerDto();
     29              }
    1330
    1431  ngOnInit(): void {
     32    this.planner = new Planner();
     33    this.plannerDto = new PlannerDto();
    1534  }
    1635
     
    1837    this.dialogRef.close();
    1938  }
     39 
     40  onFormSubmitPlanner(form: NgForm){
     41   console.log(this.planner);
     42      this.plannerService.postInitialPlanner(this.plannerDto).subscribe(
     43        data=>{
     44          console.log(data);
     45          this.router.navigate(['planner']);
     46        },
     47        error => console.log('oops', error)
     48     );
     49     window.location.reload();
     50  }
     51
    2052
    2153}
Note: See TracChangeset for help on using the changeset viewer.