import { Component, OnInit } from '@angular/core';
import { Car } from './car';import { CarService } from './car.service';
@Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css']})export class AppComponent implements OnInit {
//cars: Car[];
cars: Car="";
error = ''; success = '';
car = new Car('', 0);
constructor(private carService: CarService) { }
ngOnInit() { //this.getCars(); }
public regCar(r) { this.resetErrors(); this.carService.store1(this.car) .subscribe( res => { alert(res);
if (res === 'success') { // or this.cars['message'] // Inform the user this.success = 'Created successfully'; }
// Reset the form r.reset(); }, err => this.error = err ); }
private resetErrors(){ this.success = ''; this.error = ''; }
}
export class Car { constructor( model: string, price: number, id?: number) {}}
// pass parameter here$car = [ 'message' => 'success' ]; echo json_encode($car); } else { http_response_code(422); }