angularjs - In Angular js, how to create a form without submit button -


I tried to create a angular directive ng-smart-submit Where there is no submit button, one of the form elements loses one focus, the form is automatically submitted.

Here is a planner:

Here is the directive code:

  Angular .module ('plunker') instructions ("ngSmartSubmit", [function () {Return {restricted: 'a' is required: "ngModel", scope: {form: "= ngSmartSubmit", data: "= ngSmartModel"}, link: function (scope, element, attrs, ctrl ) {Var action; action = function (parentScope) {if (.ctrl $ dirty) {scope.form $ setPristine (); if (.ctrl $ valid) {return parentScope.update (scope.data, function (to succeed) {Ctrl $ update = succeeding ;.}) ;.} else {return parentScope throwing $ ('ngSmartSubmit :: controlInvalid');}}}. Ctrl $ Update = false; .. scope at $ parent $ ('ngSmartSubmit :: controlModified', function () {return returned $ (applied function) (ctrl $ update = false;;}};}); element Bind return ("focus", function (EVT) {return scope. $ Apply (function () {ctrl. $ Update = false;});.}), ("Stigma" function (evt) dam {return scope $ Applicable (function () {return action (scope $ parent);;}) ;.}) Tie ("keydown key press", function (evt). {If (evt.which === ENTER_KEY) {scope $ apply (function () {return action (scope $ parent);)}); Return event.preventDefault (); ..} else {return scope $ $ $ emit parents ('ngmsmtsbsmt :: control gaid');}}); }}; }];  

Please advise, how can I improve the ng-smart-submit directive.

Thanks in advance.


Comments