I have a quick and dirty app (started with the Ionic tabs template and directly coded on the home page) to check, if a picture is correct and accept or decline it. Not really special.
I send a request to a AWS Lambda function which returns me all the things I need.
And it works on “Ionic Serve”, like it should. But when I run it on my android phone with “ionic run android --device” the requests never have a response / never get fired or anything like this.
I have also implemented an additional button with a quick test. If I click it, I should get a response, but also no response.
Normally I always have an service interface, but for this application I don’t need it.
Can anyone think of any solution to solve this problem?
Here is my HTML code
<ion-header>
<ion-navbar>
<ion-title>Home</ion-title>
</ion-navbar>
</ion-header>
<ion-content padding>
<ion-refresher (ionRefresh)="doRefresh($event)">
<ion-refresher-content></ion-refresher-content>
</ion-refresher>
<h2>Snaps to check</h2>
<button ion-button (click)="makeGetRequest()">GET Request</button>
<div *ngFor="let snap of snaps">
<img [src]="snap.picUrl">
<button ion-button full (click)="send(true, snap)">
Akzeptieren
</button>
<button ion-button full (click)="send(false, snap)">
Ablehnen
</button>
</div>
</ion-content>
And here the Typescript code:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
import * as io from 'socket.io-client';
import { AlertController } from 'ionic-angular';
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
socket: any;
snaps: any[] = [];
constructor(public navCtrl: NavController, public http: Http, public alertCtrl: AlertController) {
//this.socket = io("http://ec2-35-157-45-103.eu-central-1.compute.amazonaws.com:3000"); //to listen
}
ionViewDidLoad(){
this.http.get('https://c7odbulxce.execute-api.eu-central-1.amazonaws.com/ready').map(res => res.json()).subscribe(
data => {
this.snaps = data;
},
err => {
console.log(err);
});
}
makeGetRequest() {
this.http.get("https://httpbin.org/ip")
.subscribe(data => {
var alert = this.alertCtrl.create({
title: "Your IP Address",
subTitle: data.json().origin,
buttons: ["close"]
});
alert.present();
}, error => {
console.log(JSON.stringify(error.json()));
});
}
send(allowed, snapobj) {
console.log(snapobj);
if(allowed) {
snapobj.allowed = true;
//this.socket.emit('phoneRequest', snapobj);
let index = this.snaps.indexOf(snapobj, 0);
if (index > -1) {
this.snaps.splice(index, 1);
}
} else {
snapobj.allowed = false;
//this.socket.emit('phoneRequest', snapobj);
let index = this.snaps.indexOf(snapobj, 0);
if (index > -1) {
this.snaps.splice(index, 1);
}
}
}
doRefresh(refresher) {
refresher.complete();
this.ionViewDidLoad();
}
}
Can anyone think of what I have done wrong? Why I don’t get any response on the phone?