0

我正在尝试获得结果并使用可观察的结果进行评估,但我无法获得它,请有人帮助我。

 import { Injectable } from '@angular/core';
 import {Component} from '@angular/core';
 import {Http, Response, Headers} from '@angular/http';
 import {Observable} from 'rxjs/Observable';
 import { IStudent1 } from '../interface';
 import { IStudent2 } from '../interface';
 import {ROUTER_DIRECTIVES} from '@angular/router';
 import {GetSocietyList} from './service'
  import {FORM_DIRECTIVES, FormBuilder, FormGroup, Validators, REACTIVE_FORM_DIRECTIVES} from '@angular/forms';

  @Component({
      selector: 'Search',
      templateUrl:  './components/search/search.html',
      directives: [ ROUTER_DIRECTIVES, FORM_DIRECTIVES,    REACTIVE_FORM_DIRECTIVES],
       providers : [GetSocietyList],
       inputs : ['form']
    })

    export class Search {
    property:any = 'Add';
     data: string;
     form: FormGroup;
    prop: string = 'connenct';
    details: IStudent1[];
     details1: IStudent2[];

       constructor(fbld: FormBuilder,public http: Http,private _profileservice:GetSocietyList) {
      this.details = [];
      this.http = http;
       this._profileservice.getSocietyList()
        .subscribe(details => this.details = details);

        console.log(this.details);
   this.form = fbld.group({
        name: [''],
        age: ['', Validators.required],
        class: ['', Validators.required],
        grade: ['', Validators.required]

    });

}


   edit(id): any {
//console.log(id);
this.property = 'update';
var headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded')
this.http.get('http://localhost/a2server/index.php/profile/editprofiledb/' + id, { headers: headers }).map(res=> res.json());}


}

我正在尝试获得结果并使用可观察的结果进行评估,但我无法获得它,请有人帮助我。

4

1 回答 1

1

您可以使用任何功能运算符map来获得响应。

edit(id): any {
    //console.log(id);
    this.property = 'update';
    var headers = new Headers();
    headers.append('Content-Type', 'application/x-www-form-urlencoded')
    this.http.get('http://localhost/a2server/index.php/profile/editprofiledb/' + id, { headers: headers }).map(res=> res.json());

`

然后在您的组件/指令中,您可以subscribe使用它。

constructor(private service:SomeHttpService) {
}

callingGetService() {
  this.service.edit('id').subscribe();
}

看看这里

于 2016-08-20T07:06:07.760 回答