i created form and input data to get custom respon from api and after that i test to display in console log but i get undifined in the console log and in my form i got message [Object Object].The API work well when i used manually input in the uri (url/?id=myid&code=mycode).Help me to solve this problem. Thanks before.
Here is the code
Api.php
`$code=$this->input->get(‘code’);
$id= $this->input->get(‘id’);
$x=$this->GetOne($id);
foreach($x as $y){
$finalis=$y[‘nama’];
}
$a=$this->PeriksaKode($code);
$n=$this->GetOneCode($code);
foreach ($n as $value) {
$vote=$value['vote'];
}
if($a===TRUE){
$this->UpdateCode($code, $id, $vote);
$json[] = array(
'pesan'=>"THis is the message when the condition is true"
);
}else{
$json[]=array(
'pesan'=>"False message"
);
}
echo json_encode($json);`
Service
`import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;
@Injectable()
export class KodeService {
data: any;
id:any;
kode:any;
apiUrl = ‘http://localhost/BGKadmin/index.php/BGKSS/Api/Kode’;
constructor(private http: Http) {
this.data = null;
}
load(id, kode) {
if (this.data) {
return Promise.resolve(this.data);
}
return new Promise(resolve => {
this.http.get(this.apiUrl + "/?id=" + this.id + "&"+"code=" + this.kode)
.map(res => res.json())
.subscribe(data => {
this.data = data;
resolve(this.data);
});
});
}
}
`
vote.ts
`import { Component } from ‘@angular/core’;
import { NavController, NavParams } from ‘ionic-angular’;
import {KodeService} from ‘…/…/providers/kode-service/kode-service’;
@Component({
templateUrl: ‘build/pages/vote/vote.html’,
providers: [KodeService]
})
export class VotePage {
satu;
kode:any;
pesan:any;
constructor(private nav: NavController, public param: NavParams, private kodeService: KodeService) {
this.satu = param.get(‘satu’);
}
submit(){
this.kodeService.load(this.satu.id , this.kode).then(data=> {
this.pesan =data;
});
console.log(this.pesan);
}
}
`
vote.html
` <ion-navbar *navbar favorite>
Vote
<ion-content padding class="vote">
<ion-card>
<ion-card-header>
Vote to : {{satu.nama}}
</ion-card-header>
<ion-card-content>
<center>Enter the code</center>
<ion-input type="text" placeholder="XXX" [(ngModel)]="kode" ></ion-input>
<button (click)="submit()">submit</button>
</ion-card-content>
</ion-card>
</ion-content>
`