Is there a change in Angular 2 HTTP service after upgrading to Angular 2 rc4?
I have spent the entire day going through Angular HTTP client documentation and searching on Stack Overflow, but I can't seem to find the solution to my problem.
Here are snippets of my code implementation and the error I am encountering. Can anyone please help me figure out what I am doing wrong?
Below is my code:
import { Restaurant } from '../index'
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { Injectable } from '@angular/core';
import 'rxjs/Rx';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class RestaurantService {
constructor(private _http: Http){}
addRestaurant(restaurant: Restaurant): Observable<Restaurant> {
let body = JSON.stringify({restaurant});
let headers = new Headers({ 'Content-Type':'application/json'});
let options = new RequestOptions({ headers: headers});
console.log(body);
return this._http.post('http://localhost:3000/restaurant', body, options)
.map(this.extractData)
.catch(this.errorHandler)
}
private extractData(res: Response) {
let body = res.json();
return body;
}
private errorHandler(error:any) {
return Observable.throw(error.json());
}
}
The service is implemented in my code below:
import { Component, OnInit, OnDestroy } from '@angular/core';
import { REACTIVE_FORM_DIRECTIVES, FormArray, FORM_DIRECTIVES, FormControl, FormGroup } from '@angular/forms';
import { Restaurant } from './index';
import { RestaurantService } from '../../index';
@Component({
moduleId: module.id,
selector: 'sd-restaurant-form',
templateUrl: 'restaurant-form.component.html',
styleUrls: ['restaurant-form.component.html'],
directives: [REACTIVE_FORM_DIRECTIVES]
})
export class RestaurantFormComponent implements OnInit, OnDestroy {
formActive: boolean = true;
restaurantForm = new FormGroup( {
.........
.........
});
constructor(public restaurantService: RestaurantService) { }
onSubmit() {
let value = this.restaurantForm.value;
............
............
............
this.restaurantService.addRestaurant(this.restaurant)
.subscribe(
res =>{ this.result = res,
console.log(this.result)},
error=> {this.error = error.
console.log(this.error)}
)
}
ngOnInit() {
for (let i=0; i<24; i++) {
if( i === 0) {
this.timesHour.push(0 +''+i);
}
else if ((Math.log10(i)+1) < 2 ) {
this.timesHour.push(0 +''+i);
} else {
this.timesHour.push(String(i));
}
}
for (let i=0; i<60; i++) {
if( i === 0) {
this.timesMin.push(0 +''+i);
}
else if ((Math.log10(i)+1) < 2 ) {
this.timesMin.push(0 +''+i);
} else {
this.timesMin.push(String(i));
}
}
}
ngOnDestroy() {}
}
This is the error message I am receiving:
EXCEPTION: Error: Uncaught (in promise): Can't resolve all parameters for RestaurantFormComponent: (?).
EXCEPTION: Error: Uncaught (in promise): Can't resolve all parameters for RestaurantFormComponent: (?).
STACKTRACE:
Error: Uncaught (in promise): Can't resolve all parameters for RestaurantFormComponent: (?).
at resolvePromise (zone.js?1467669664341:538)
at zone.js?1467669664341:515
at ZoneDelegate.invoke (zone.js?1467669664341:323)
at Object.onInvoke (core.umd.js:9100)
at ZoneDelegate.invoke (zone.js?1467669664341:322)
at Zone.run (zone.js?1467669664341:216)
at zone.js?1467669664341:571
at ZoneDelegate.invokeTask (zone.js?1467669664341:356)
at Object.onInvokeTask (core.umd.js:9091)
at ZoneDelegate.invokeTask (zone.js?1467669664341:355)
Unhandled Promise rejection: Can't resolve all parameters for RestaurantFormComponent: (?). ; Zone: angular ; Task: Promise.then ; Value: BaseException$1 {message: "Can't resolve all parameters for RestaurantFormComponent: (?).", stack: "Error: Can't resolve all parameters for Restaurant…ngular/compiler/bundles/compiler.umd.js:14640:81)"}
Error: Uncaught (in promise): Can't resolve all parameters for RestaurantFormComponent: (?).(…)