Hi
I would really like some help.
I wanna check if there is internet connection to test if i understand how to use it.
I’m using Phonegap 3.4 and i’m using the basic ionic example(The pet information example).
In the “PetIndexCtrl” conroller i’m trying to console.log the status and i get "unknown"
This is my code:
.controller('PetIndexCtrl', function($scope, PetService) {
// "Pets" is a service returning mock data (services.js)
//var networkConnectionType = navigator.network.connection.type;
console.log(navigator.network);
$scope.pets = PetService.all();
})
What am i doing wrong?
Please note that when i’m using the Hello Phonegap example(the code that comes when installing) it works(i’ve installed the network plugin)
10x!
@doronsever Perhaps you need a new topic for your question since it’s about actually using the core plugin functionality instead of wrapping it in Angular logic.
But to have a quick go on your question; I think you’re running it in the (desktop) browser instead of simulating through an emulator or running on an iPhone?
When running in the browser, you don’t have Cordova functionality on hand and the navigator.connection.type will return unknown if it’s available in the first place.
Please try to read and understand the above examples of Angular services wrapped around Cordova plugins. In my opinion, they are much friendlier to use.
For example if you would use my CordovaNetwork service; just inject CordovaNetwork in your Controller and then you can do something like:
if(CordovaNetwork.isOnline()) {}
And another side note; always wrap your Cordova plugin calls inside a deviceready event callback. If the device isn’t ready when you try to execute the Cordova stuff, you will get unexpected results.
Hi
Thank you for your reply.
I’ve tested it everywhere: Iphone simulator(i’m on mac os), Android emulator, Ripple and on my own Android phone.
Each one of them return the same result: “unknown”
I’ve also implemented your service and injected it in the controller like so:
.controller('PetIndexCtrl', function($scope, PetService, CordovaNetwork) {
// "Pets" is a service returning mock data (services.js)
alert(CordovaNetwork.isOnline());
$scope.pets = PetService.all();
})
I get “false” in the alert, in each platform also.
The only way that i can get something to work is like so:
can any one help with this code please?
I try to upload pictures form m gallery but it doesn’t work
controller.js:
$scope.allImages =[];
function UploadPicture(imageURI){
$scope.allImages[$scope.intf] = imageURI;
$scope.intf=$scope.intf+1;
$scope.$apply();
}
$scope.FindPicture = function () {
navigator.camera.getPicture(UploadPicture, function(imageData) {
alert(‘get picture failed’);
},{
quality: 50,
destinationType: navigator.camera.DestinationType.FILE_URI,
sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY
}
);
}
and the index.html: