I want to prevent default click action on submit button:

I have a haml form with this button:

= f.submit 'Publish', "ng-click" => "submit($event)"

a controller:

$scope.submit = function(event) {
    if(some_condition) {
      event.preventDefault(); //This is working on development. But not working on production environment.
      //show modal with a message
    }
  }
};

I don't want to ask if form it's not valid. "some_condition" It's not related with validations.

Question:

What am I possibly doing wrong o production env?

or what is the right path to take to solve this? (I'm new with angular)

I'm using AngularJS v1.2.0rc1 (dev and production)

有帮助吗?

解决方案

Consider using ng-submit on the form instead of ng-click on the submit button. As the documentation tells: "Enables binding angular expressions to onsubmit events. Additionally it prevents the default action (which for form means sending the request to the server and reloading the current page) but only if the form does not contain an action attribute."

http://docs.angularjs.org/api/ng.directive:ngSubmit

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top