I copied a custom directive that watches for changes on form file inputs.
angular.module('customDirective', [])
.directive('ngFileInputChange', function() {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var onChangeHandler = scope.$eval(attrs.ngFileInputChange);
element.bind('change', onChangeHandler);
}
};
});
Then I use it in the template like so:
<input ng-model="vm.image" ng-file-input-change="vm.base64Test" ...>
And this works fine.
However, this doesn't work:
<input ng-model="vm.image" ng-file-input-change="vm.base64Test()" ...>
Note the ()
at the end of base64Test()
. With a generic ng-click
, the parenthesis are fine, or even required (how else would I pass arguments to the function?) but with the custom directive, parenthesis cause an error.
I only have a vague understanding of what scope.$eval(attrs.ngFileInputChange)
is actually doing, so maybe I could make some change in that?
EDIT:
I should also add that I need access to some scope variables. For example, if I didn't have to use the custom directive, I would write something like this in my controller:
vm.base64Test(associatedData){
console.log(associatedData);
}
And then:
<input ng-change("vm.base64Test(vm.associatedData)">
But ng-change doesn't watch file input contents and the custom directive doesn't allow arguments (other than event), so I'm stuck.