错误,其他路由工作正常,但这给了我错误
core.es5.js:1084 ERROR错误:未捕获(在承诺中):错误:没有ConnectionBackend的提供者! 错误
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule, Http } from '@angular/http';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { ContactComponent } from './contact/contact.component';
import { AboutComponent } from './about/about.component';
import { ProductsComponent } from './products/products.component';
import { NotFoundComponent } from './not-found/not-found.component';
import { appRouting } from "app/app.routing";
import { MaterialComponent } from './products/material/material.component';
import { ConveyorsComponent} from'./products/conveyors/conveyors.component';
import { AutomatedComponent } from './products/automated/automated.component';
import { TestingComponent } from './products/testing/testing.component';
import { LeakageComponent } from './products/leakage/leakage.component';
import { ProductService } from "app/products/services/product.service";
import { Slide } from "app/home/slide.component";
import { Carousel } from "app/home/carousel.component";
import { AgmCoreModule } from 'angular2-google-maps/core';
import { ContactService } from "app/contact/contact.service";
@NgModule({
declarations: [
AppComponent,
HomeComponent,
ContactComponent,
AboutComponent,
ProductsComponent,
NotFoundComponent,
MaterialComponent,
ConveyorsComponent,
AutomatedComponent,
TestingComponent,
LeakageComponent,
Carousel,
Slide
],
imports: [
BrowserModule,
FormsModule,
appRouting,
HttpModule,
ReactiveFormsModule,
AgmCoreModule.forRoot({
})
],
providers: [ProductService, ContactService],
bootstrap: [AppComponent],
schemas: [ CUSTOM_ELEMENTS_SCHEMA ]
})
export class AppModule { }
contact.component.ts
import { Component, OnInit, Injector } from '@angular/core';
import { Image } from "app/home/image.interface";
import {Email} from"./email.interface";
import { FormGroup, FormControl, Validators } from "@angular/forms";
import { Http, BaseRequestOptions } from "@angular/http";
import { ContactService } from "app/contact/contact.service";
import {MockBackend} from '@angular/http/testing';
@Component({
selector: 'app-contact',
templateUrl: './contact.component.html',
styleUrls: ['./contact.component.css'],
providers: [Http, ContactService]
})
export class ContactComponent implements OnInit {
form: FormGroup;
submitted: boolean = false;
public images = IMAGES;
public imagesm = IMAGESM;
private data;
constructor(private _contactService : ContactService) { }
uname: string;
email_id: string;
contact_no: string;
comment: string;
lat: number = 18.676172;
lng: number = 73.787607;
ngOnInit() {
this.form= new FormGroup({
uname: new FormControl(""),
email_id: new FormControl(""),
contact_no: new FormControl(""),
comment: new FormControl("")
});
console.log(this.form);
}
public message: Email = {uname: '', email_id: '',contact_no:'', comment:''};
onSubmit() {
this._contactService.postEmail(this.message).subscribe(
response => this.handleResponse(response),
error => this.handleResponse(error)
);
}
handleResponse(response){
console.log(`msg is: {response.status}`);
if(response.status =='success'){
this.message = {uname: '', email_id: '',contact_no:'', comment: ''};
alert('hello');
}
if(response.status =='error'){
alert('error');
}
}
}
var IMAGES: Image[] = [
{ "title": "", "url": "../../assets/images/Banners6.jpg" },];
var IMAGESM: Image[] = [
{ "title": "", "url": "../../assets/images/Mobile/Contact_Banners_mobile.jpg" },];
contact.service.ts
import {Injectable} from '@angular/core';
import {Http, Response,Headers, RequestOptions} from '@angular/http';
import {Observable} from 'rxjs/Rx';
import {Email} from './email.interface';
@Injectable()
export class ContactService {
constructor (private _http: Http) {}
private _contactUrl = 'app/contact/email.php';
postEmail(newMail: Email): Observable<string>{
let body =`uname=${newMail.uname}&email_id=${newMail.email_id}&contact_no=${newMail.contact_no}&comment=${newMail.comment}`;
let headers = new Headers({ 'Content-Type': 'application/x-www-form-urlencoded' });
let options = new RequestOptions({ headers: headers });
return this._http.post(this._contactUrl, body, options)
.map(res => <string> res.json())
.catch(this.handleError)
}
private handleError (error: Response) {
console.error('Error in retrieving news: ' + error);
return Observable.throw(error.json().error || 'Server error');
}
}
请给我解决方案