Angular中的jQuery日期选择器 [英] JQuery date pickers in Angular

查看:119
本文介绍了Angular中的jQuery日期选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular应用程序中使用了一个jqueryUI日期选择器.日期选择器已为其分配了ng-change事件.当用户直接在文本框中使用键盘输入日期时,这将触发OK,但是当使用日期的弹出对话框时,该命令将无法执行.有人知道为什么会这样吗?

I have a jqueryUI date picker used in an Angular application. The date picker has an ng-change event assigned to it. This fires off OK when the user enters a date with the keyboard directly in the textbox but fails to execute when the popup dialog for the date is used. Does anybody know why this might be?

推荐答案

不建议将jQuery与Angular一起使用(或什至在当今所有情况下)-您遇到怪异行为的原因是因为jQuery包装了诸如NodeList之类的本机DOM对象等在自定义jQuery对象中.

It is not advised to use jQuery with Angular (or even at all nowadays) - the reason you are experiencing weird behaviour is because jQuery wraps Native DOM objects like NodeList etc. in a custom jQuery object.

因此,运行$("div")时返回的内容不是对 元素或NodeList,它是一个jQuery对象.这意味着一个jQuery 对象具有与对象完全不同的方法 引用DOM元素,包含元素的数组或任何类型的 节点列表.但是,这些本机对象始终实时出现 代码-jQuery尝试将其抽象化,您总会拥有 来处理它们,即使只是将它们包装在$()中.

So, what is returned when you run $("div") is not a reference to an element, or a NodeList, it’s a jQuery object. This means that a jQuery object has completely different methods available to it than a reference to a DOM element, an array with elements or any type of NodeList. However, these native objects come up all the time in real code — as much as jQuery tries to abstract them away, you always have to deal with them, even if it’s just wrapping them in $().

您可能会期望-ngIf,ngModel和其他基本Angular指令等指令严重依赖本机DOM 对象.

As you might expect - directives like ngIf, ngModel and other fundamental Angular directives rely heavily on native DOM objects.

那对jQuery + Angular意味着什么?

好吧,如果Angular正在寻找 HTMLInputElement ,但是它找到了一个完全不同的包装对象- $("input"),其中包含许多 strange方法-至少可以说是错误的行为.

Well if Angular is looking for a HTMLInputElement but it finds a completely different object wrapped - $("input") which contains many strange methods for which Angular has no API - you are going to get erroneous behavior to say the least.

当涉及到预构建的组件时,有许多更好的替代方案.

There are many better alternatives out there when it comes to pre-built components.

ngx-bootstrap

primeNG

material2

这篇关于Angular中的jQuery日期选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆