0

I am attempting to use an ng-submit call to fire a submit event to my custom directive, but it isn't firing.

Here is a plunk that illustrates my problem.

<div ng-controller="MyCtrl">
    <form name="loginForm" ng-submit="login()" novalidate="">
        <input type="submit" class='please-wait' value="Submit Me" />
    </form>
</div>

js code:

app.directive('pleaseWait', function () {
    return {
        restrict: "C",
        compile: function (element) {
            element.on('submit', function (e) {
                alert('Submit called');
            });

            element.on('click', function (e) {
                alert('Click called');
            });
        }
    };
});

http://plnkr.co/edit/lwHPVJI75q8bvVoSX1WP?p=preview

What am I doing wrong?

3
  • 2
    submit is an event of form, not input Commented Jul 25, 2014 at 2:01
  • 1
    Moving the class please-wait to the form fixed it. Commented Jul 25, 2014 at 2:03
  • re-post as answer and I'll accept. Commented Jul 25, 2014 at 2:11

1 Answer 1

4

"submit" is not an event on the input element but is an event on the form so the directive is listening for an event it won't receive.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.