19 Aug 2017

How to check internet Connection using Ionic V 1


Add Network information cordova plugin

Syntax:   

cordova plugin add cordova-plugin-network-information


// Check for network connection
    if(window.Connection) {
      if(navigator.connection.type == Connection.NONE) {
        $ionicPopup.confirm({
          title: 'No Internet Connection',
          content: 'Please check your Internet connection and try again.'
        })
        .then(function(result) {
          if(!result) {
            ionic.Platform.exitApp();
          }
        });
      }
    }

Note: You must test only mobile.

16 Aug 2017

Ionic Get Current date [Get current date using Angularjs]

Show Full Date: (Method 1)

$scope.currDate = new Date();

alert($scope.currDate )

Output like this:
Wed Aug 16 2017 12:11:06 GMT+0530 (India Standard Time)



Show Full Date: (Method 2)

var date = new Date();

$scope.FromDate = date.getFullYear() + '-' + ('0' + (date.getMonth() + 1)).slice(-2) + '-' + ('0' +
date.getDate()).slice(-2);

Output like this:
2017-08-16


Get Current Date Only:
var date = new Date();

$cur_date = date.getDate();
alert($cur_date)

Get Current Month Only:
var date = new Date();
$cur_mon = date.getMonth() + 1;
alert($cur_mon)

Get Current Year:
var date = new Date();
$cur_year = date.getFullYear();
alert($cur_year)


3 Aug 2017

Error with $http.get in angularJS — Response :Success & Error ionic

// Simple GET request example:
$http({
  method: 'GET',
  url: '/someUrl'
}).then(function successCallback(response) {
    // this callback will be called asynchronously
    // when the response is available
     var data = response.data;
    var status = response.status;
    var statusText = response.statusText;
    var headers = response.headers;
    var config = response.config;

    $scope.user = data;
    console.log(data);

  }, function errorCallback(response) {
    // called asynchronously if an error occurs
    // or server returns response with an error status.
     var data = response.data;
    var status = response.status;
    var statusText = response.statusText;
    var headers = response.headers;
    var config = response.config;

    $scope.user = data;
    console.log(data);
  });



More Details: 
https://docs.angularjs.org/api/ng/service/$http