Posted in Angular, Code Snippets

AngularJS – UI-Router : Multiple states with same URL

Usually, with angular ui-router, we can have one url for a single state something like this:

.state('app', {
  url: "/home",
  templateUrl: "....",
  controller: "myController",
  roles: ['administrator','authenticated']

Continue reading “AngularJS – UI-Router : Multiple states with same URL”

Posted in Angular, Code Snippets

Make bootstrap button group to work with Angular

Many developers face the trouble to make the Twitter Bootstrap’s button group, toggle buttons to work with Angular. For instance, following is the code for button group – btn-group

<div class="btn-group">
         Radio 1
         Radio 2
         Radio 3

But ng-model doesn’t seem to work with this.

Continue reading “Make bootstrap button group to work with Angular”

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”