I want my directive to support ng-change events but instead of defining a particular function to call when ng-change is triggered, I want to enable ng-change to take any sort of function with single or multiple parameters and execute it. I could think of of two ways but dont know which is right or which will work. it goes something like this:
Method 1:
HTML:
<currency-input width="200px" id="iextz" ng-model="currency1" ng-change="someFunction(argument1,argument2,.....)" currency="$" decimals="2"></currency-input>
JS:
numericApp.directive('currencyInput',........
...................................
return {
restrict: 'E',
scope:{
ngModel : "=",
id : "@"
},
link: function($scope, $elm, $attrs) {
........................................
*//some logic to execute the function passed to ng-change*
executeNgChangeFucntion(){
...........
...........
};
}]);
Method 2
HTML:
<currency-input width="200px" id="iextz" ng-model="currency1" ng-change="change(someFunctionWithArguments)" currency="$" decimals="2"></currency-input>
JS:
numericApp.directive('currencyInput',........
...................................
return {
restrict: 'E',
scope:{
ngModel : "=",
id : "@"
},
link: function($scope, $elm, $attrs) {
........................................
//ng-change handler
$scope.change = function(someFunctionWithArguments){
//execute someFuncitonWithArguments
..........................
};
}]);
I'm not really experienced in advanced concepts of AngularJS, so whatever I could think of I put it out here. It would be a great help if someone could provide some inputs. Thanks in advance!
Actually I'm building a numeric field component which would take in numbers and format it according to the set currency, set decimal digits etc., that sort of stuff, anyway the important part is that it's for someone else to use(let's say a client). Folks can use this component in their application and they need to process whatever input comes into the field with ng-change. They have their own event handlers. It could be anything. So I need to provide a way so that they can pass one of their functions to be executed whenever the input changes(as in what happens with n-change). For ex.:
<decimal-input ng-model="employees.calculatedChangeAmounts[job.id][jobChangeReasonCodes[$index]].changeAmount" decimals="2" ng-change="recalculate.salaryAmount($index, job)"></decimal-input>
I hope that helps in clearing any doubts. Now please help in solving mine, thanks!