gpt4 book ai didi

带有 AngularJS 的 jQuery 日期选择器 : "TypeError: element.datePicker is not a function"

转载 作者:行者123 更新时间:2023-12-03 23:02:26 25 4
gpt4 key购买 nike

我尝试在 AngularJS 应用程序中使用 jQuery datepicker,但收到以下错误消息:

jQuery datepicker with AngularJS: "TypeError: element.datePicker is not a function"

我正在使用此答案中的代码: jQuery ui datepicker with Angularjs

这是来自同一答案的有效 fiddle : http://jsfiddle.net/kevinj/TAeNF/2/

这是我正在使用的完整代码:

<html>
<head>
<script src="/js/angular.min.js"></script>
<script src="/lib/jquery/jquery-1.12.0.min.js"></script>
<script src="/lib/jquery/jquery-ui-1.11.4.min.js"></script>
<link rel="stylesheet" type="text/css" href="/lib/jquery/jquery-ui-1.11.4.min.css">
</head>

<body ng-app="app">

<script>
var datePicker = angular.module('app', []);

datePicker.directive('jqdatepicker', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
element.datePicker({
dateFormat: 'DD, d MM, yy',
onSelect: function (date) {
scope.date = date;
scope.$apply();
}
});
}
};
});
</script>

<p><input type="text" ng-model="date" jqdatepicker></p>
<p>{{ date }}</p>

</body>
</html>

我到底做错了什么?谢谢!

最佳答案

当您在 jQuery 之前加载 AngularJS 时,默认情况下将使用 jQLite,它是 Angular 本身内部存在的较小的 jQuery API。

基本上,您需要在 Angular js 之前包含 jQuery,以便在查询 DOM 时默认使用 jQuery api。

否则您需要显式使用$(element)

NOTE

Make sure both the jQuery library version should be same, jQuery & jQuery.ui both.

Demo Fiddle

关于带有 AngularJS 的 jQuery 日期选择器 : "TypeError: element.datePicker is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35162270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com