我尝试配置时收到此输出。为什么发布空值。最诚挚的问候
{_body: "↵↵ ↵", status: 200, ok: true, statusText: "OK", headers: Headers…}
我的file.component.ts
import {Component, OnInit} from '@angular/core';
import {NgForm} from '@angular/forms';
// import { Observable } from 'rxjs/Rx';
import {Http, Response, Headers, Request, RequestOptions, RequestMethod, URLSearchParams} from '@angular/http';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-header',
templateUrl: './header.component.html',
styleUrls: ['./header.component.css']
})
export class HeaderComponent implements OnInit {
// title: string = 'My first angular2-google-maps project';
lat: number = -1.2590509;
lng: number = 36.7836213;
success: string;
login: {fname?: string, lname?: string, emailadd?: string, phone?: string, message?: string} = {};
constructor(public http: Http) {
}
ngOnInit() {
}
//regassets
onregassets(form: NgForm) {
this.submitdata();
// this.methodt();
}
submitdata(): void {
var link = 'http://africatechpoint.com/isbi/testangular.php';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let urlSearchParams = new URLSearchParams();
urlSearchParams.append('Firstname', this.login.fname);
urlSearchParams.append('Lastname', this.login.lname);
urlSearchParams.append('EmailAddress', this.login.emailadd);
urlSearchParams.append('Phone', this.login.phone);
urlSearchParams.append('Message', this.login.message);
let body = urlSearchParams.toString()
this.http.post(link, body, {headers: headers})
.subscribe(data => {
this.success = this.login.lname;
console.log("Guess what is happening", this.success);
console.log("sasa mtu wangu", data);
console.log("Empty Data", data.text());
}, error => {
console.log(body);
});
}
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { HeaderComponent } from './header/header.component';
import { FooterComComponent } from './footer-com/footer-com.component';
import { AgmCoreModule } from 'angular2-google-maps/core';
@NgModule({
declarations: [
AppComponent,
HeaderComponent,
FooterComComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AgmCoreModule.forRoot({
apiKey: 'AIzaSyDpBltUoIDcL2KUa3zCiu1TV18tLz_7gTQ'
})
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>AngularTester</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root>Loading...</app-root>
</body>
</html>
答案 0 :(得分:0)
克隆你提到的回购(github.com/mainakanyi/africaGeek)后,我不得不重新安装angular-cli。尝试提供应用时出现以下错误:
$ ng serve
Unable to find "@angular/cli" in devDependencies.
The package "angular-cli" has been deprecated and renamed to "@angular/cli".
Please take the following steps to avoid issues:
"npm uninstall --save-dev angular-cli"
"npm install --save-dev @angular/cli@latest"
修正了angular-cli问题。但是,运行ng serve
我得到了:
Environment configuration does not contain "environmentSource" entry.
A new environmentSource entry replaces the previous source entry inside environments.
出现该错误的原因是您在angular-cli.json中缺少"environmentSource": "environments/environment.ts"
。只需在第14行的angular-cli中添加(在environments
之上),所以它看起来像这样:
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
该回购没有您在问题中提到的file.component.ts
。