Submit form on pressing Enter with AngularJS 这个问题使用html5按钮,但我使用Angular Material Button作为
<div class="card-action no-border text-right">
<md-button class="color-primary sign-btn" ng-disabled="logForm.$invalid" ng-click="login()"> Sign In</md-button>
</div>
但如何使用它
答案 0 :(得分:3)
您可以创建一个Enter指令,如下所示:
'use strict';
angular.module('directives')
.directive('eopdEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if (event.which === 13) {
scope.$apply(function () {
scope.$eval(attrs.eopdEnter, {'event': event});
});
event.preventDefault();
}
});
};
});
以这种方式使用它:
<div class="card-action no-border text-right">
<md-button class="color-primary sign-btn" eopd-enter="login()" ng-disabled="logForm.$invalid" ng-click="login()"> Sign In</md-button>
</div>