web-dave / ng-essential-workshop

0 stars 0 forks source link

Show Vehicle Details #14

Open web-dave opened 4 years ago

web-dave commented 4 years ago
web-dave commented 4 years ago

generate

  ng g c fleet/vehicle-details
web-dave commented 4 years ago

vehicle-list.component.ts

 constructor(
    private service: VehicleService, 
    private router: Router,
    private route: ActivatedRoute) { }

  selectVehicle(vehicle: IVehicle) {
    this.router.navigate([vehicle.id], {relativeTo: this.route});
  }
web-dave commented 4 years ago

fleet-routing.module.ts

  children: [{
      path: '',
      component: VehicleListComponent
    }, {
      path: ':id',
      component: VehicleDetailsComponent
    }]
web-dave commented 4 years ago

vehicle-details.component.html (example)

<div class="panel panel-default" *ngIf="vehicle" >
   <div class="panel-heading">{{vehicle.make}} ({{vehicle.model}})</div>
  <div class="panel-body">
    <p>{{vehicle.description}}  <span class="badge">Sitze: {{vehicle.seats}}</span> </p>
    <p>{{vehicle.type}}</p>
  </div>
  <div class="panel-footer">{{vehicle.department}}</div>
</div>
web-dave commented 4 years ago

vehicle-details.component.ts

  constructor(
      private service: FleetService,
      private router: Router,
      private route: ActivatedRoute) { }

  ngOnInit() {
    this.route
      .params
      .subscribe((params: {id: string}) => {
        this.service.getVehicle(params.id)
          .subscribe(v => {
            console.log('!!', v);
            this.vehicle= v;
          });
      });
  }
web-dave commented 4 years ago

NEXT