2017-10-10 195 views
0

我正在運行Angular4平均應用程序,我想用PrimeNG Schedule在日曆中顯示事件。時間表建立在FullCalendar上,它反過來需要jQuery和Moment.js的工作。儘管我使用了ap-ng2-fullcalendar版本,因爲它與Angular4更兼容。用PrimeNG將平均角度4應用導入FullCalendar Schedule

所以我用npm安裝了jQuery,Moment,FullCalendar和primeNG Scedule。

我已經把這些進口的app.module.ts

import {CalendarModule} from "ap-angular2-fullcalendar"; 
import {ScheduleModule} from 'primeng/components/schedule/schedule'; 

(和進口:[...])

而在HTML組件有這個(PrimeNG指令) :

<p-schedule [events]="projects"></p-schedule> 

但是當我運行該項目,我得到一個錯誤:

ERROR ReferenceError: jQuery is not defined 

如何在我的應用中獲取jQuery(和Moment)?我可以從node_module/jQuery的/ DIST中的jquery.js文件複製到我的公共文件夾並將其添加到html像這樣:

<script src="/js/plugins/jquery.js"></script> 

但是,這可能是不正確的做法,然後我跑項目時得到這個:

TypeError: this.schedule.fullCalendar is not a function 

我認爲,一些JS文件丟失在我的項目和jQuery和時刻需要某種一些手動進口,但不知道怎麼辦。 注意:我使用webpack。

謝謝!

+0

有幾種方法可以解決這個問題。你應該看看[angular-cli-wiki on global scripts](https://github.com/angular/angular-cli/wiki/stories-global-scripts)。這應該給你一些關於如何去做你想要的東西的想法。 – Andresson

+0

您是否使用Angular CLI? –

+0

不,我不使用CLI,我用webpack打字。我想我現在明白了,這是https://github.com/moment/moment/issues/4228中的一個錯誤,以及我如何導入沒有TypeScript(type)定義的第3方庫的一些誤解。 ap-ng2-fullcalendar模塊實際上使得FullCalendar可以在我的設置中訪問。瞭解所有這些內容也是有用的,https://www.youtube.com/watch?v=qWSPog9Fz-o – user1043194

回答