0
我想從我的數據庫中獲取記錄,我寫了observables和下面的代碼,我沒有得到任何記錄。可以有人請建議幫助。如何從觀察數據庫中獲取數據
我的組件,
import { Injectable } from '@angular/core';
import {Component} from '@angular/core';
import {Http, Response, Headers} from '@angular/http';
import {Observable} from 'rxjs/Observable';
import { IDetails } from './details';
@Component({
templateUrl: './components/search/search.html',
})
@Injectable()
export class Search {
details:IDetails[];
constructor(public http: Http) {
this.http = http;
}
submit(id):any{
var headers = new Headers();
var id = localStorage.getItem('social_id')
headers.append('Content-Type','application/x-www-form-urlencoded')
this.http.get('http://localhost/a2server/index.php/profile/search/'+id,{headers:headers})
.subscribe(
response => { <IDetails[]> response.json(); })
}
}
我想從我的數據庫獲取的記錄,我寫了觀測,並用下面的代碼我沒有得到任何records.Can有人請建議幫助。
謝謝丹,它的工作又是什麼使用步驟可觀察 –
MMR
@nlr_p的目的 - 我想你在評論中問爲什麼需要一個觀察的。我已經更新了答案以反映這一點。 –