Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-app="app">
  
  <div ng-controller="ctrl">
    
    <form ng-submit="normalFn($event)" hook="hookFn()">
      <input type="submit">
    </form>
    
  </div>
</body>
</html>
 
var deps = [];
var app  = angular.module('app', deps);
app.config(function ($provide) {
  $provide.decorator('ngSubmitDirective', function ($delegate, $parse) {
    var directive = $delegate[0];
    var origCompile = directive.compile;
    
    directive.compile = function (el, attrs) {
      origCompile.apply(this, arguments);
      
      if (attrs.hook) {
        return function (scope, el, attrs) {
          var fn = $parse(attrs['ngSubmit']);   
          var hook = $parse(attrs['hook']);
        
          el.on('submit', function (event) {
            scope.$apply(function () {
              fn(scope,   { $event: event });
              hook(scope, { $event: event });
            });
          });          
        };
      }
    };
    
    return $delegate;
  });
});
app.controller('ctrl', function ($scope) {
  $scope.normalFn = function ($event) {
    console.log('normal action called', $event);
  };
  
  $scope.hookFn = function ($event) {
    console.log('hook called', $event);
  };
});
app.directive('dir', function () {
  return {
    
  };
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers