특정 조건에 따라 데이터를 표시하려는 API가 있습니다. 여기에서 세부 정보를 얻고 있습니다.
내 서비스 구성 요소,
@Injectable()
export class GetAllList {
id = localStorage.getItem('social_id')
private _productUrl = 'http://localhost/a2server/index.php/profile/getProfile/'+this.id;
constructor(private _http: Http) { }
getList(): Observable<IDetails[]> {
return this._http.get(this._productUrl)
.map((response: Response) => {
return <IDetails[]> response.json();
});
}
}
My Observable,
export interface IDetails{
profile_id:number;
firstname: string;
lastname: string;
profilename: string;
phone:string;
email:string;
address:string;
}
내 주요 구성 요소에서 이러한 서비스를 다음과 같이 사용하고 있습니다.
ngOnInit(){
this._service.getList()
.subscribe(details => this.details = details);
}
잘 작동합니다. 콘솔에서 이름을 확인하고 싶다면 어떻게해야하나요? 이렇게 .....
ngOnInit(){
this._service.getList()
.subscribe(details => this.details = details);
console.log(this.details[0].firstname);
}
누구든지 제발 도움을 제안 할 수 있습니까?
아래 제안 된대로 사용하십시오.
ngOnInit(){
this._service.getList().subscribe((data) =>{
this.details = data;
this.details.forEach((detail)=>{
console.log(detail.firstname);
})
});
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다