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

后端 未结 4 1575
后悔当初
后悔当初 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:43

    Another way is to add your js functions defined in a separate file to a global scope. So in your js file you can add sth like this:

    $(document).ready(function() {
        window.example = example;
    }
    

    Then in your component typeScript file, right below the imports, you can declare this function:

    declare function example(input): void;
    

    And then you can just simply use this function in the component methods.

提交回复
热议问题