0

I have followed a tutorial How to use a Javascript script in Typescript (Angular 5 CLI) about how to use javascript/jquery in Angular. I have followed the steps but in the component the file can't be found.

I have created a very simple jquery-file named

jqfilejs.js

and downloaded

jquery-3.3.1.min.js

.

According to the tutorial

"scripts": [
        "../node_modules/jquery/dist/jquery.min.js",
        "assets/js/someJqueryThing.js",...

I have added those lines to angular.cli.json but with my filename

"assets/js/jqfilejs.js"

and I changed jqueryfileadress to

"../node_modules/jquery/dist/jquery-3.3.1.min.js"

. Then I created the directories above and added jqfilejs.js in assets/js and added jquery-3.3.1.min.js to node_modules/jquery/dist/.

According to the tutorial I am going to add this line

    import('jqfilejs');
    declare function playSound():void;

to the typescriptfile. I use it in a component.ts-file. But the import('jqfilejs') declaration get

[ts] Cannot find module 'jqfilejs'.

message. Do anyone know what I have done wrong? Thanks

2 Answers 2

0

Add assets folder to :

"apps": [
{
  "root": "src",
  "outDir": "dist",
  "assets": [
    "assets"     // <<<   
  ],
}]

in angular.cli.json .

6
  • Can it have something with the downloaded jQueryfile? I cut it from code.jquery.com/jquery-3.3.1.min.js and saved it as jquery-3.3.1.min.js Aug 8, 2018 at 10:24
  • install by this code npm install [email protected] and use "../node_modules/jquery/dist/jquery-3.3.1.min.js" Aug 8, 2018 at 10:47
  • JQuary installed now, still can't find jqfilejs.js. Do I need to install that one to? I only moved it to assets/js without doing any installation in cmd Aug 8, 2018 at 11:00
  • use : "../src/assets/js/jqfilejs.js" Aug 8, 2018 at 11:47
  • In angular-cli.json? Did not do a difference Aug 8, 2018 at 11:56
0

I used this tutorial instead and use jQuery in Angular where needed instead of downloading library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.