我在我的項目中添加了第三方包(jQuery,colorbox)。首先,我對NPM安裝擲和後我添加到 「角cli.json」Angular 2中的第三方庫
"scripts": [
"../node_modules/jquery/dist/jquery.js",
"../node_modules/jquery-colorbox/jquery.colorbox.js", ....
和我聲明在組件,
declare var $:any;
declare var colorbox:any;
and the code
ngAfterViewInit(){
$(document).ready(function(){
$(".alma1").colorbox({rel:'alma1'});
});
}
和視圖
<a class="alma1" href="{{pic.pictureURL}}" title="{{pic.desc}}">
<img class="alma" src="{{pic.pictureURL}}" alt="{{pic.desc}}">
</a>
當我第一次點擊鏈接時,它會將我帶到谷歌firebase存儲鏈接頁面,當我回到網頁並再次點擊鏈接後,colorbox包工作正常。我在ngAfterViewInit()中調用,但看起來像不存在。 爲什麼第一次不工作?
提供plunker –