I'm trying so send a form (using a directive) when a property in the model changes (so I watch the property), but when I trigger the submit event, I get the error: "Error: [$rootScope:inprog] $digest already in progress", how can I avoid this error, here is my code:
app.directive("autoSubmit", function(){
return {
link: function(scope, element, attrs){
scope.$watch("valid", function(){
if(scope.valid == 1) {
console.log("send form");
element.triggerHandler("submit");
}
});
}
}
});
Heres is he plunk: http://plnkr.co/edit/cosJLkhUEKv55G8uU1Ea (to reproduce the error, just change the value of the textbox to 1)
Thanks in advance for your help.