2016-07-07 53 views
4

我想在我的應用程序中使用Primeng日曆(http://www.primefaces.org/primeng/#/calendar)當我運行代碼時,出現錯誤:ReferenceError:未定義jQuery。另一個Primeng指令正常工作。如果我刪除<p-calendar>錯誤消失。Primeng日曆錯誤 - 未定義JQuery

我已經導入並在我的應用中包含日曆。 順便說一下,我正在使用角度,路由器和窗體的最新版本。在此之前,我有這個問題:https://github.com/primefaces/primeng/issues/549並通過更新表單提供程序來修復它。

<p-calendar [(ngModel)]="date"></p-calendar> 

堆棧跟蹤摘錄:

ReferenceError: jQuery is not defined 
    at Calendar.ngAfterViewInit (eval at <anonymous> (http://localhost:8080/js/app.js:930:2), <anonymous>:44:90) 
    at DebugAppView._View_AddShipmentComponent0.detectChangesInternal (AddShipmentComponent.template.js:930:59) 
    at DebugAppView.AppView.detectChanges (eval at <anonymous> (http://localhost:8080/js/vendor.js:716:2), <anonymous>:243:14) 
    at DebugAppView.detectChanges (eval at <anonymous> (http://localhost:8080/js/vendor.js:716:2), <anonymous>:348:44) 
+0

如果你沒有一個,嘗試包括您的index.html參考,jQuery的。 – mifish

+1

''依賴關係是:'jQuery UI Datepicker和DateTimePicker' –

回答

8

您需要添加的依賴關係:

<!-- Datetimepicker, Slider, Schedule --> 
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> 
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script> 
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-ui-timepicker-addon/1.6.1/jquery-ui-timepicker-addon.min.js"></script> 
+2

這太傷心了:( – daveoncode

+1

嗯,在光明的一面團隊正在努力從日曆中刪除第三方依賴關係:) – Sergio

+0

Beta19具有本機日曆,而不是jQuery根據。 http://blog.primefaces.org/?p=4149 –

3

您也可以只添加這一點:

<script src="node_modules/primeui/primeui-ng-all.min.js"></script>

或者,如果您使用的角度,CLI和我一樣,你可以npm i primeui,並添加到您的angular-cli.json:在beta.19

"scripts": ["../node_modules/primeui/primeui-ng-all.min.js"]

更新

的jQuery的依賴已被刪除。

參考:http://blog.primefaces.org/?p=4149