[image: angular-webinar-31st.jpg] Title: new angular development features and improvements with error handling webinar by google employees
About Angular: Angular is a Typescript-based open-source front-end web application platform led by the Angular Team at Google and by a community of individuals and corporations. What we’ll cover in this webinar... Any error you can fix after this webinar 1. Angular error handling with latest strategies 2. New tips to write clean and per-formant angular application 3. Improving the testability of the angular app 4. Add caching to APIs and Migrating to PWA 5. State Management in Angular 6. User Activity logging with Azure Application Insights 7. Integrate with any technology Speaker: Ryan Russul who is a speaker and having 8 years of experience in UI development and worked as senior solution architect, practising code re-usability and enterprise practices in angular development among all teams who were responsible for angular development. Join in webinar: http://ovpurl.com/c2V5oNgM On Thursday, October 18, 2018 at 4:49:24 PM UTC+5:30, [email protected] wrote: > > Am trying to post data to php backend and display json call response > message *success* but am having the following errors > > > *Error in src/app/car.service.ts(42,5): error type* > *observable<Object> is not assignable to type Observable<String>* > > Here is *app.component.ts* code > > 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 = ''; > } > > } > > > Here is the *Car.services.ts* > import { Injectable } from '@angular/core'; > import { HttpClient, HttpErrorResponse, HttpParams } from > '@angular/common/http'; > > import { Observable, throwError } from 'rxjs'; > import { map, catchError } from 'rxjs/operators'; > > import { Car } from './car'; > > > @Injectable({ > providedIn: 'root' > }) > export class CarService { > > baseUrl = 'http://localhost/angular-project1/api'; > > > //cars: ; > > //cars: Car[]; > > constructor(private http: HttpClient) { } > > store1(car: Car): Observable<String> { > return this.http.post(`${this.baseUrl}/store1`, { data: car }) > .pipe( > catchError(this.handleError)); > } > > private handleError(error: HttpErrorResponse) { > console.log(error); > > // return an observable with a user friendly message > return throwError('Error! something went wrong.'); > } > } > > > > here is the* car.ts* > > > > > *export class Car { constructor( model: string, price: number, > id?: number) {}}store.php* > > > *// pass parameter here* > *$car = [* > * 'message' => 'success'* > * ];* > > * echo json_encode($car);* > * }* > * else* > * {* > * http_response_code(422);* > * }* > > > > > > > > -- You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/angular. For more options, visit https://groups.google.com/d/optout.
