vishnu
vishnu

Reputation: 4599

calling directive function from controller using angularjs

I have written custom price format directive using angularjs.

It will trigger an event while 'blur' event happened. But, how do i call the function while opening(by default) the page.. I need to call directive function while opening the page.

<input name="amt" type="text" class="form-control text-right" name="amt" id="amt" data-ng-model="rowUnderEdit.amount" format-currency required>

my directive:

.directive('formatCurrency', function() {
       return { 
              require: 'ngModel',
              link: function($scope, $element, $attrs, ngModelCtrl) {
                     var listener = function(){
                         console.log('>>>>>>>>');
                         ---------------
                         --------------

                         $element.val(currency);
                        }
                     }
                     $element.bind('blur', listener);                     
              }
       }
});

Upvotes: 0

Views: 57

Answers (1)

Scottie
Scottie

Reputation: 11308

Simply call the function...

    ....
    $element.bind('blur', listener);                     

    listener();
}

Upvotes: 1

Related Questions