2016-05-23 25 views
2

我試圖讓JScolor庫在我的angular 2網站上工作。我相當新,所以我不知道問題是什麼。在angular 2中導入jscolor庫

在我的組件導入我喜歡圖書館:

Import 'the/path/to/the/library'; 

而我給了HTML元素的類jscolor讓庫知道哪個元素它應該工作。

這是隻是永遠不會工作,因爲角2框架不會像這樣工作,或者我忘記了什麼?

+0

你得到任何錯誤?你看到加載在網絡標籤中的JScolor文件嗎?我猜你需要將它添加到SystemJS – Tomer

+0

是的,它被加載,沒有錯誤。我現在正在嘗試rinukkusu的解決方案! –

回答

0

在你index.html添加腳本標籤加載jscolor.js

<script src='the/path/to/the/library'></script> 

我產生了打字稿類型確定指標文件,它應該基本上在這裏工作:https://gist.github.com/rinukkusu/63ae4530561c89a95c9c3d716c0a7b3b

declare var jscolor: { 
    dir: string; 
    binding: boolean; 
    preloading: boolean; 
    install:() => void; 
    init:() => void; 
    getDir:() => any; 
    detectDir:() => any; 
    bind:() => void; 
    preload:() => void; 
    images: { 
     pad: number[]; 
     sld: number[]; 
     cross: number[]; 
     arrow: number[]; 
    }; 
    imgRequire: {}; 
    imgLoaded: {}; 
    requireImage: (filename: any) => void; 
    loadImage: (filename: any) => void; 
    fetchElement: (mixed: any) => any; 
    addEvent: (el: any, evnt: any, func: any) => void; 
    fireEvent: (el: any, evnt: any) => void; 
    getElementPos: (e: any) => number[]; 
    getElementSize: (e: any) => any[]; 
    getMousePos: (e: any) => any[]; 
    getViewPos:() => number[]; 
    getViewSize:() => number[]; 
    URI: (uri: any) => void; 
    color: (target: any, prop: any) => void; 
}; 

在組件,或無論你需要它在你的文件頂部引用這樣的類型定義文件:

///<reference path="path/to/the/jscolor.d.ts"/> 

或者你可以看看 https://github.com/Alberplz/angular2-color-picker

+0

我一直在尋找angular2-color-picker,但有一些奇怪的問題。我添加了一個問題,但還沒有回覆。 –