Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  143] [ 2]  / answers: 1 / hits: 82752  / 7 Years ago, thu, july 6, 2017, 12:00:00

I have an angular 4 application and I have a javascript component that I created in a javascript file : timeline.js. The javascript component works well but I want to use it with angular 4. So, I put my js file in the folder assets/js/timeline.js.



In the file index.html, I call my js file with <script src=assets/js/timeline.js></script> and in app.component.ts, I have :



var timeline = new Timeline(timelineVisualization)


So, normally, the timeline is created in the div which has id=timelineVisualization.



But it doesn't work and I have an error on the new Timeline : Cannot find name Timeline.



So, do you know how I can do to call the Timeline constructor from timeline.js ?


More From » angular

 Answers
112

you simply need to do



 import * as Timeline from '../assets/js/timeline.js';


You can also do (at the top of your file) :



declare var Timeline: any;


Check also below for good practices.


[#57200] Monday, July 3, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jack

Total Points: 557
Total Questions: 96
Total Answers: 80

Location: Saint Helena
Member since Mon, Jan 16, 2023
1 Year ago
jack questions
Sun, Jan 31, 21, 00:00, 3 Years ago
Thu, Dec 10, 20, 00:00, 4 Years ago
Sat, Aug 1, 20, 00:00, 4 Years ago
Fri, Apr 17, 20, 00:00, 4 Years ago
Wed, Aug 14, 19, 00:00, 5 Years ago
;