Posted in Angular, Code Snippets

AngularJS: Recursive function with deferred promise

Deferred promise is a great way to handle async calls synchronously. When we use recursive function, we may wonder how to handle the defer variable. It is as simple as:

some_function = function(some_var1, some_var2, def) {
   var deferred = def || $q.defer(); // Use def when it is recursive call
       url: url,
       method: "POST",
   }).success(function(result) {
   }).error(function(result, status) {
       some_function(some_var1, some_var2, deferred);
   return deferred.promise;

Bold texts are those that needs to be added to handle deferred promise in recursive calls.

Continue reading “AngularJS: Recursive function with deferred promise”

Posted in Code Snippets, Javascript

Get filename from URL with extension

Get the filename from the URL or path using Javascript:

Consider the URL:

var url = ""

Method 1:


Method 2: Regular Expression

url.replace(/^.*[\\\/]/, '')

Both method returns


But when URL is something like this with query parameters:

var url = ""

Then above methods will return:


In order to remove query parameters from the URL, use:


This again returns


Query parameters reside in next index.



Posted in Bootstrap, Code Snippets, Javascript

Quick Fix: Scrolling and Focus when multiple bootstrap modals are open

When more than one modal is opened you might have noticed that after the latter modal loses its focus, the former modal loses its scrolling option, rather page’s body scrolls (if exists, otherwise no scrollbar!). There is a quick fix for this:

Continue reading “Quick Fix: Scrolling and Focus when multiple bootstrap modals are open”