How can i use foxTooltip with Angular?

巧了我就是萌 提交于 2019-12-17 21:23:55

问题


I want to import the library foxToolTip with angular.

I tried import * as foxToolTip from 'fox.tooltip.js';

but the [ts] doesn't found the module fox.tooltip.js

I installed the version : fox.tooltip.js: 1.0.13,


回答1:


In case of Angular 5, inside .angular-cli.json's scripts array, add the path to fox.tooltip.js

"scripts": [
    "../node_modules/fox.tooltip.js/dist/foxToolTip.min.js"
],

In case of Angular 6, inside angular.json's scripts array, add the path to fox.tooltip.js without ../

"scripts": [
    "node_modules/fox.tooltip.js/dist/foxToolTip.min.js"
],

and then, inside your Component, just declare a variable named foxToolTip like this:

declare var foxToolTip: any;

You don't need to do

import * as foxToolTip from 'fox.tooltip.js'

as your the compiler will throw an error stating that:

Cannot find module 'fox.tooltip.js'.

Just adding the script to the scripts array in .angular-cli will add it to the global scope and you'll be able to access it from your components.

Also, make sure that you call any function on it inside the ngAfterViewInit lifecycle hook method as it tries to access the DOM elements by id.



来源:https://stackoverflow.com/questions/51895876/how-can-i-use-foxtooltip-with-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!