简体   繁体   English

jQuery和Angular:在ng-keydown中添加两个功能

[英]JQuery and Angular: Add two functions in ng-keydown

Adding two functions in ng-keydown through the use of jQuery attr 通过使用jQuery attr在ng-keydown中添加两个功能

How can I do this the right way. 我该怎么做才正确。

$('#id').attr('ng-keydown', 'maxinput(), numericOnly()');

I agree with @pixelbits that you should create a custom validator for the purpose you are trying to achieve. 我同意@pixelbits的观点,您应该出于尝试实现的目的创建一个自定义验证器 In fact, you can even use ng-maxlength and set input type to number to have the validation you require OOTB. 实际上,您甚至可以使用ng-maxlength并将输入类型设置number来进行需要OOTB的验证。

But if you really want to call multiple functions in an ng-* handler (it can be click, keydown etc), you should separate calls with semicolon ; 但是,如果您真的想在ng-*处理程序中调用多个函数(可以是click,keydown等),则应使用分号将调用分开; instead of comma. 而不是逗号。

You might also want to read how to think in Angular way with jQuery background . 您可能还想阅读如何在jQuery背景下以角度的方式思考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM