2017-07-20 65 views
0

沒有工作,靜態的HTML很容易使用(http://t1m0n.name/air-datepicker/docs/):空氣在日期選擇器4角

<html> 
    <head> 
     <link href="dist/css/datepicker.min.css" rel="stylesheet" type="text/css"> 
     <script src="dist/js/datepicker.min.js"></script> 

     <!-- Include English language --> 
     <script src="dist/js/i18n/datepicker.en.js"></script> 
    </head> 
</html> 

但我不`噸知道如何與角4

使用它安裝空氣日期選擇器與

npm i air-datepicker --save 

在分量寫

import 'jquery/dist/jquery.min.js'; 
import 'air-datepicker/dist/js/datepicker.js'; 

但輸入不使用它

<input type='text' class="datepicker-here" data-position="right top" /> 

如果加上這個js文件「.angular-cli.json」這不行

"scripts": [ 
    "../node_modules/air-datepicker/dist/js/datepicker.js" 

回答

0

你並不需要的js文件導入到組件。步驟加氣臺或者其他jQuery插件到您的項目

  1. 安裝NPM的依賴

    npm install jquery air-datepicker --save 
    
  2. 讓知道的WebPack應加什麼js和css捆綁(.angular-cli文件)

    "scripts": [ 
        "../node_modules/jquery/dist/jquery.min.js", 
        "../node_modules/air-datepicker/dist/js/datepicker.js", 
        "../node_modules/air-datepicker/dist/js/i18n/datepicker.en.js" 
        ] 
    
        "styles": [ 
        "styles.scss", 
        "../node_modules/air-datepicker/dist/css/datepicker.min.css" 
        ] 
    
  3. ngAfterViewInit()初始化插件組件的方法
    ($('#datepicker') as any).datepicker();

好像你不能datepicker-here類初始化插件,你應該使用手動初始化。

如何使用與角2的jQuery,你可以看到here

如果它`不明確的,你可以聯繫我