我正在尝试将数据发布到数据库,但我收到错误“无法读取未定义的属性'帖子'。我正在尝试学习angular2可以有人帮助我。
import {Component} from '@angular/component'
import {FormBuilder, Validators, ControlGroup, FORM_DIRECTIVES} from '@angular/common';
import {HTTP_PROVIDERS, Http, Response} from '@angular/http';
@Component({
selector: 'profile-form',
directives: [FORM_DIRECTIVES],
templateUrl: './components/profile/profile.html',
providers: [FormBuilder, HTTP_PROVIDERS]
})
export class Profile {
data;
form;
constructor(private http: Http) {}
onSubmit(): void {
this.http.post(
'http://localhost/a2server/index.php/profile/addprofile',
JSON.stringify({
firstname: 'bar',
lastname: 'foo'
}))
.subscribe((res: Response) => {
this.data = res.json();
});
}
}