Hi I have follow code:
<form ng-submit="ctrl.commitEdit(sign)">
<input ng-model="sign.Value">
<input ng-model="sign.Date">
<textarea ng-model="sign.Comment"></textarea>
<select ng-model="sign.Property"></select>
<button type="submit">Save</button>
</form>
With my form around my components I tried to save my edits in two ways (in my form I call in the ng-submit a method from my controller, which saves my edits):
So I would like to save with pressing "enter" in every way, on the input, select and textarea. How can I do this?
Thanks
All you need to do is use ngKeyup.
https://docs.angularjs.org/api/ng/directive/ngKeyup
Just bind it with enter key code which is 13 and call your function
Moreover here is a directive you can implement for your purpose.
app.directive('ngEnter', function() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 13) {
scope.$apply(function(){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.