Good afternoon, I have a problem, I need to call a directive within a controller method but I get the following error: TypeError: Can not create property 'directiveFunction' on string '0', I do not know what I'm doing wrong, the next Code portion is part of the driver where I call the directive.
if ($scope.count == "1") {
if ($scope.monto === null || $scope.monto.length === 0 || typeof $scope.monto === 'undefined' ) {
$scope.monto = (num);
} else {
$scope.monto = ($scope.monto + "" + num);
// Llamada a la directiva
$scope.dirOptions.directiveFunction();
}
app.directive('blurToCurrency', function($filter){
return {
scope: {
amount : '='
},
link: function(scope, el, attrs){
angular.extend(scope.amount, {
directiveFunction: function(){
el.val($filter('currency')(scope.amount,""));
el.bind('focus', function(){
el.val(scope.amount);
});
el.bind('input', function(){
scope.amount = el.val();
scope.$apply();
});
el.bind('blur', function(){
el.val($filter('currency')(scope.amount, ""));
});
},
});
}
}
});
<div class="col-sm-9 select">
<label for="inlineFormInput" class="sr-only">Name</label>
<input id="inlineFormInput" type="text" placeholder="Monto" blur-to-currency amount="monto" size="4" ng-focus="count = 1" class="mx-sm-3 form-control">
</div>