ngCordova, when Cordova meets Angular.js

      ngCordova, when Cordova meets Angular.js无评论

Cordova with the power of AngularJS. ngCordova is a set of AngularJS extensions on top of the Cordova API to make it easier to build, test, and deploy Cordova apps with AngularJS.

Nowadays CSS and JavaScript are awesome. If you are not writing too dirty in your code to reduce the performance, you are hardly to figure an app is built with native codes or just a web app.

Angular.js is trend in latest year and become most popular framework in web development. Angular.js is built by Google and maintained by community, which is huge!

If you familiar with Angular.js and want to build a mobile application with Cordova. ngCordova maybe your choice.

ngCordova actually is a wrapper class forCordovainto Angular.js module. You actually no need to understand how Cordova works because it wrapped by Angular.js pattern.

Example

Camera is one of the popular function that Cordova provided. In traditional way, you have to code like this:

navigator.camera.getPicture(onSuccess, onFail, { quality: 50,
destinationType: Camera.DestinationType.DATA_URL
});
function onSuccess(imageData) {
var image = document.getElementById('myImage');
image.src = "data:image/jpeg;base64," + imageData;
}
function onFail(message) {
alert('Failed because: ' + message);
}

But in ngCordova angular.js way:

module.controller('PictureCtrl', function($scope, $cordovaCamera) {
$scope.takePicture = function() {
$cordovaCamera.getPicture({
// See all the possible Camera options from the Camera docs [1]:
/// https://github.com/apache/cordova-plugin-camera/blob/master/doc/index.md#cameraoptions
}).then(function(imageData) {
// Success! Image data is here
}, function(err) {
// An error occured. Show a message to the user
});
}
});

The code looks more Angular.js way right? It would be great to keep all your angular.js projects look in a same pattern.

ngCordova is built by Ionic team, which is a team who developedIonic framework.

发表评论

电子邮件地址不会被公开。 必填项已用*标注