我正在使用ng-submit
(因为它对键盘友好)并且对于具有单个按钮的表单它可以正常工作。使用多个按钮,我创建了这个有趣的构造
<form ng-submit="submit()">
...
<button ng-if=... ng-click="setAction('create')"...>create</button>
<button ng-if=... ng-click="setAction('update')"...>update</button>
<button ng-if=... ng-click="setAction('delete')"...>delete</button>
</form>
和
一样var action;
$scope.setAction = function(a) {
action = a;
}
$scope.submit = function() {
var a = action || findTheDefaultAction();
action = "";
return myActions[a]();
};
它有效,但我发现它非常难看:
ng-click
ng-submit
findTheDefaultAction
重复ng-if
条件中的逻辑。有更好的方法吗?