I have a function defined in a directive called old(), currently the button executes this function when clicked. I want the old() function to be replaced with a new() function when the directive is loaded. The new function should receive (this.form) as a parameter, where "form" represents the name of my form. I attempted the following, but it did not work:
attrs.$set('ngClick', 'new(this.form)');
The new() function did not execute as expected. How can I achieve this? I specifically need to make these changes within a directive; while it might be possible in a controller, I am looking for a solution within a directive so that I could apply it to my actual project. Thank you.
app.directive('validation', function ($timeout) {
return {
restrict: 'AE',
require: 'ngModel',
link: function (scope, element, attrs, ngModel) {
if (!ngModel){
return;
}
scope.old= function(){
alert("old")
}
//attrs.$set('ngClick', 'new(this.form)');
scope.new= function(form){
alert("new");
console.log(form)
}
}
};
});