I made an App on android, using Ionic. Everything was working fine on my computer, but there are to things that did not work once the app was on on my phone.
The first one is maybe more difficult. I have a data on Mysql database, and fetch that data using php echoing it as json. Then i retrieve it with angular using jsonp. it works fine on my computer, but nothing happens on my phone. Here is my JS file:
$(function(){
var App = angular.module("App");
App.controller('companySearchController',function($scope,GetAPI){
$scope.groups = [];
$scope.message = "Fyrirtækja Leit";
$scope.showOrNot = false;
$scope.search2 = function(searchText){
GetAPI.getCompany2(searchText).then(onCompanyComplete);
};
var onCompanyComplete = function(data){
console.log(data['data']);
for(var x = 0; x<data['data'].length;x++){
var tempArray = [];
for(var i = 0; i<5; i++){
tempArray.push(data['data'][x][i]);
}
$scope.groups.push(tempArray);
console.log(tempArray);
}
};
$scope.toggleGroup = function(group) {
if ($scope.isGroupShown(group)) {
$scope.shownGroup = null;
} else {
$scope.shownGroup = group;
}
};
$scope.isGroupShown = function(group) {
return $scope.shownGroup === group;
};
});
}());
And the PHP file:
$<?php
$fname = $_GET['firstname'];
$pdo = require_once('dbconfig.php');
$sth=$PDO->prepare("SELECT * FROM company WHERE name LIKE '$fname%' LIMIT 200");
$sth->execute();
$result = $sth ->fetchAll();
$jsonData = json_encode($result);
echo $_GET['callback'] . '('.$jsonData.')';
Like i said, there is nothing that gets displayed on my phone, but when i run it in a browser on my computer, everything works fine.
And then there is the Input problem. I have some inputs that are all linked, and all change when the other changes. When i'm typing in the input, after i have typed the second number it auto fills in a number after that one. Everything works fine on my computer.
Here is the JS file:
$(function(){
var App = angular.module("App");
App.controller('currencyController',function($scope,GetAPI){
//$scope.run = false;
$scope.search = function(){
GetAPI.getCurrency().then(onCarComplete);
};
var onCurrencyComplete = function(data){
$scope.currencyData = data;
starter(1000);
};
var starter = function (price) {
for(var i = 0; i<$scope.currencyData.length;i++){
$scope.currencyData[i]['forApp'] = parseFloat(price/$scope.currencyData[i]['askValue']).toFixed(2);
$scope.currencyData[i]['forAppReal'] = price/$scope.currencyData[i]['askValue'];
}
};
$scope.changeCurrency = function(changed){
var isk = changed['forApp']*changed['askValue'];
console.log(isk);
//console.log(changed['shortName'] + " " + changed['forApp']+ " is: "+ isk);
calculate(isk);
changed['forApp'] = parseFloat(changed['forApp']).toFixed(0);
};
var calculate = function(isk){
for(var i = 0; i<$scope.currencyData.length;i++) {
var stuff = isk/$scope.currencyData[i]['askValue'];
stuff = parseFloat(stuff).toFixed(2);
$scope.currencyData[i]['forApp'] = (stuff);
}
};
$scope.clicked = function(item){
item['forApp'] = parseInt(item['forApp']).toFixed(0);
};
GetAPI.getCurrency().then(onCurrencyComplete);
});
}());
And the HTML file:
$<ion-view title="companys" class="fullIon">
<div class="list currencyList col-80 col-offset-10">
<label class="item item-input item-floating-label" data-ng-repeat="item in currencyData" data-ng-click="clicked(item)">
<input type="text" value="{{item.forApp}}" ng-model="item.forApp" ng-change="changeCurrency(item)"><p class="longNameText">{{item.longName}}</p>
</label>
</div>
</ion-view>