Friday, 1 August 2014

AngularJs: order by filter

Use order by like this:

<tr ng-repeat="emp in empList | orderBy:joiningDate">
</tr>

Above code will show you emp list in ascending order of joining date.

<tr ng-repeat="emp in empList | orderBy:-joiningDate">
</tr>

You can see I used - (hyphen) in above code. Due to this hyphen employee list will show in descending order of joining date.

Thursday, 31 July 2014

How to show alternate image if source image is not found?

A example is here

Phonegap/Cordova: Download file

To download file in cordova you have to add following plugins:

1. File
2. File System
3. File Transfer

And example is here:
var app = {
    // Application Constructor
    initialize: function() {
        this.bindEvents();
    },
    // Bind Event Listeners
    //
    // Bind any events that are required on startup. Common events are:
    // 'load', 'deviceready', 'offline', and 'online'.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
    },
    // deviceready Event Handler
    //
    // The scope of 'this' is the event. In order to call the 'receivedEvent'
    // function, we must explicitly call 'app.receivedEvent(...);'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
    },
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, app.fileSystemSuccess, app.fileSystemFail);
        console.log('Received Event: ' + id);
    },

fileSystemSuccess: function(fileSystem) {
var directoryEntry = fileSystem.root;
directoryEntry.getDirectory("folder_rahul", {create: true, exclusive: false}, app.onDirectorySuccess, app.onDirectoryFail);
var rootdir = fileSystem.root;
var fp = rootdir.toURL();
alert(fp);
fp = fp + "folder_rahul/120px-State-lib-sum.png";
var fileTransfer = new FileTransfer();
   fileTransfer.download("http://data-gov.tw.rpi.edu/w/images/thumb/b/b1/State-lib-sum.png/120px-State-lib-sum.png",fp,
   function(entry) {
       alert("download complete: " + entry.fullPath);
   },
   function(error) {
cosnole.log(error);
       alert("download error source " + error.source);
       alert("download error target " + error.target);
       alert("upload error code" + error.code);
   }
);
},

fileSystemFail: function(evt) {
    alert("Failed---"+evt.target.error.code);
},

onDirectorySuccess: function(parent) {
console.log(parent);
},

onDirectoryFail: function(error) {
alert("Unable to create new directory: " + error.code);
}
};

More details are here and here

Monday, 28 July 2014

Angularjs filtered array length

In this example, I am applying a filter on list and after that I am getting the length.

<tr ng-show="showdate && (yourlist | filter:searchEmp).length > 0"><td class='appointment_header' style="font-weight:bold;" colspan="3"><span> {{----}}</span></td></tr>

Tuesday, 22 July 2014

Is it valid to replace http:// with // in a script src=“http://…”?

Yes, It is valid and good.

We don't have to think about protocol It can be http or https.

It is very helpful when we use CDN or any Google/Facebook or any other API.