Include .js file in an Angular Component 4

0

How can a .js file be included in an Angular 4 component?

I have searched and in all the examples of how to use jQuery in a component write directly from the code inside the export of the class as here :

export class AppComponent {
    // script
}

What methods are there to "import" or indicate the path of an existing script? And what would be the best way to organize the scripts to be able to reuse it throughout the project? Or what, by agreement, is usually done in projects with Angular

    
asked by gmarsi 26.12.2017 в 20:23
source

1 answer

0

Add the path of your scripts to the file .angular-cli.json :

{
    "scripts": [
        "ruta/de/tu/script1.js",
        "ruta/de/tu/script2.js",
        "ruta/de/tu/script3.js"
    ]
}

Then for its use the most usual is the following:

declare var $: any; // Para jQuery
    
answered by 26.12.2017 в 23:29