[英]ng-submit on dropdown and textarea
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): 使用围绕组件的表单,我尝试以两种方式保存编辑(在表单中,我从控制器调用ng-submit提交一个方法,以保存所做的编辑):
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. 您需要做的就是使用ngKeyup。
https://docs.angularjs.org/api/ng/directive/ngKeyup https://docs.angularjs.org/api/ng/directive/ngKeyup
Just bind it with enter key code which is 13 and call your function 只需将其与输入密钥代码13绑定,然后调用您的函数
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();
}
});
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.