Initial Journal service:


.factory('Journal', function() {
  var journal = [
    {
      "title": "My 1st Entry",
      "content": "This is a sample entry."
    }
  ];

  return {
    all: function() {
      return journal;
    },
    remove: function(entry) {
      journal.splice(journal.indexOf(entry), 1);
    },
    get: function(entryId) {
      for (var i = 0; i < journal.length; i++) {
        if (journal[i].id === parseInt(entryId)) {
          return journal[i];
        }
      }
      return null;
    }
  };
})

Journal service with add:


.factory('Journal', function() {
  var journal = [
    {
      "title": "My 1st Entry",
      "content": "This is a sample entry."
    }
  ];

  return {
    all: function() {
      return journal;
    },
    remove: function(entry) {
      journal.splice(journal.indexOf(entry), 1);
    },
    get: function(entryId) {
      for (var i = 0; i < journal.length; i++) {
        if (journal[i].id === parseInt(entryId)) {
          return journal[i];
        }
      }
      return null;
    },
    add: function(entry) {
      journal.push(entry);
    }
  };
})

Quick modal:

Inject:


$ionicModal

To create modal:


$ionicModal.fromTemplateUrl('templates/modal.html', {
  scope: $scope,
  animation: 'slide-in-up'
}).then(function(modal) {
  $scope.modal = modal;
});

To show modal:


$scope.modal.show();

To hide modal:


$scope.modal.hide();

Our initial add modal:


Quick popup:

Inject:


$ionicPopup

To create popup:


var alertPopup = $ionicPopup.alert({
  title: 'STOP RIGHT THERE!',
  template: 'Please fill out all fields.',
  buttons: [{ // Array[Object] (optional). Buttons to place in the popup footer.
    text: 'Say you\'re sorry.',
    type: 'button-royal'
  }]
});

Journal service with localstorage:


.factory('Journal', function() {
  // Give us an example object
  var journal = [
    {
      "title": "My 1st Entry",
      "content": "This is a sample entry."
    }
  ];

  // If we have a journal object, use that!
  if (localStorage.journal)
    journal = JSON.parse(localStorage.journal);

  var save = function() {
    localStorage.journal = JSON.stringify(journal);
  };

  return {
    all: function() {
      return journal;
    },
    remove: function(entry) {
      journal.splice(journal.indexOf(entry), 1);
      save();
    },
    get: function(entryId) {
      for (var i = 0; i < journal.length; i++) {
        if (journal[i].id === parseInt(entryId)) {
          return journal[i];
        }
      }
      return null;
    },
    add: function(entry) {
      journal.push(entry);
      save();
    }
  };
})

Take a picture:

To add:


cordova plugin add cordova-plugin-camera

Inject:


$cordovaCamera

Use:


var options = {
  quality: 50,
  sourceType: Camera.PictureSourceType.CAMERA,
  cameraDirection: 0, 
  destinationType: Camera.DestinationType.DATA_URL,
  encodingType: Camera.EncodingType.JPEG,
  targetWidth: 500,
  targetHeight: 600,
  saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function (imageData) {
  var photo = "data:image/jpeg;base64," + imageData;
  addPost(null, photo);
}, function (err) {
  // error
  console.error(err);
  takeAFakePicture();
});

Geolocation:

To add:


cordova plugin add cordova-plugin-geolocation

Inject:


$cordovaGeolocation

Use:


var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
  .getCurrentPosition(posOptions)
  .then(function (position) {
    var lat  = position.coords.latitude
    var long = position.coords.longitude
  }, function(err) {
    // error
  });