我在我的项目中添加了第三方包(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 –