How to use javascript functions in an Angular 2 component from a different file

后端 未结 4 1570
后悔当初
后悔当初 2020-12-15 20:14

I have a javascript file that contains some data manipulation functions (No DOM manipulation at all) such as float rounding, mathematical operations, ...etc

my js fi

4条回答
  •  暖寄归人
    2020-12-15 20:41

    I finally found out the answer; it was to basically make a typings file and add it to the project.

    The problem was related to TypeScript not Angular2. In typeScript you can't simply use any JS file without having a definition (typing) file that declares the types of the vars, the params of the functions, as well as the returns. check this link to know how to create one.

提交回复
热议问题