2017-05-29 67 views
1

我想在使用typeahead.js的Angular2應用程序中實現typeahead。在打字稿文件中,我添加了以下導入段。javascript:提供的參數不匹配呼叫目標的任何簽名

import initTypeahead = require("../../../assets/js/init/dashboard.js"); 

dashboard.d.ts

declare function initTypeahead(data:any,id:any): void; 
export = initTypeahead(data,id); 

dashboard.js

if ('undefined' !== typeof module) { 

    module.exports = function initTypeahead(data, element) { 
    console.log(data); 
    console.log(element); 
    var _values = new Bloodhound({ 
     datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'), 
     queryTokenizer: Bloodhound.tokenizers.whitespace, 
     local: data 
    }); 
    _values.initialize(); 

    var elt = $(element); 
    elt.tagsinput({ 
     itemValue: 'code', 
     itemText: 'value', 
     typeaheadjs: { 
     name: '_values', 
     displayKey: 'value', 
     source: _values.ttAdapter() 
     } 
    }); 
    } 
} 

然後在打字稿添加下列行。

private getCities(): void { 
    this.componentsService.getCriteriaValues(this.product, "city").subscribe(res => { 
    initTypeahead(res.returnData, '#city'); // error at this line 

    }); 


} 

以下錯誤顯示出來的納克服務

Supplied parameters do not match any signature of call target. 

任何建議高度讚賞。

謝謝

+0

你使用的是Angular-cli嗎? – SrAxi

+0

@SrAxi,是的,我正在使用angular-cli – Rose18

回答

1

如果使用角CLI:

角cli.json:

"scripts": [ 
     "assets/js/init/dashboard.js" 
], 

當你使用它:

import '../../../assets/js/init/dashboard.js'; 

declare function initTypeahead(data:any,id:any): void; 

你先要d到從你的angular-cli.json加載庫,然後你可以將這些代碼實際導入你的組件,以便使用它的方法,變量等。

相關問題