Open web-dave opened 4 years ago
ng g c fleet/vehicle-edit
{
path: ':id/edit',
component: VehicleEditComponent
}
import { FormsModule } from '@angular/forms';
import ...
@NgModule({
imports: [
CommonModule,
FleetRoutingModule,
FormsModule
],
exports: [],
declarations: [...],
providers: [...]
})
export class FleetModule { }
<form *ngIf="vehicle" #form="ngForm" (ngSubmit)="saveVehicle()">
<div class="form-group">
<label for="make">Make</label>
<input
type="text"
id="make"
name="make"
required minlength="6"
[(ngModel)]="vehicle.make"
#make="ngModel">
<div [hidden]="!make.errors?.required || make.pristine">Enter a Make</div>
</div>
...
<div>
<button type="submit" [disabled]="!form.valid">Save</button>
<a class="btn btn-default btn-sm" [routerLink]="['..']">X</a>
</div>
</form>
saveVehicle() {
this.service.updateVehicle(this.vehicle)
.subscribe(() => {
this.router.navigate(['..'],{relativeTo:this.route});
});
}
updateVehicle(vehicle: IVehicle): Observable<IVehicle> {
const url = `${this.restRoot}/${vehicle.id}`;
return this.http.put<IVehicle>(url, vehicle);
}
vehicle-edit
componentFormsModule
into FleetModule