Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
423 views
in Technique[技术] by (71.8m points)

angular5 - How can i use foxTooltip with Angular?

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,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...