http angular2中未定义的帖子错误

时间:2016-06-21 09:36:59

标签: http typescript angular

我正在尝试将数据发布到数据库,但我收到错误“无法读取未定义的属性'帖子'。我正在尝试学习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();

       });
   }
 }

0 个答案:

没有答案