Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jQuery is not defined in js file under assets/js/*.js #3509

Closed
johnqiuwan opened this issue Dec 10, 2016 · 3 comments
Closed

jQuery is not defined in js file under assets/js/*.js #3509

johnqiuwan opened this issue Dec 10, 2016 · 3 comments

Comments

@johnqiuwan
Copy link

johnqiuwan commented Dec 10, 2016

OS?

Windows 8.1

Versions.

ng version: 1.0.0-beta.22-1

node version: 5.10.1

Repro steps.

  1. the project created with angular-cli (ng new ...)

  2. Included jquery and boostrap basded on the steps in doc, and everything is working

  3. Added a "plugins.js" file under "assets/js/plugins.js" folder

  4. Included "plugins.js" file before the tag in index.html file

  5. ng server

  6. chrome developer console shows "jQuery is not definded" @plugins.js

The log given by the failure.

jQuery is not defined @plugins.js

Mention any other details that might be useful.

The code in "plugins.js" is something like

jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing,{ ...

@hassanasad
Copy link

hassanasad commented Dec 11, 2016

If you are using bootstrap from NPM, i believe you can call it from node-packages.

For instance, i am using bootstrap.min.css from angular-cli.json:

...
"tsconfig": "tsconfig.json",
"prefix": "app",
"mobile": false,
"styles": [
   "../node_modules/bootstrap/dist/css/bootstrap.min.css" <- LIKE THIS
],
"scripts": [],
...      

Perhaps you can try by using the scripts argument.

P.S: Its actually not recommended to use jQuery with Angular2 projects as DOM manipulation is handled by Angular. If you want to use bootstrap, try using the ng2-bootstrap npm package with Angular

@filipesilva
Copy link
Contributor

@johnqiuwan you shouldn't add script tags directly to index.html because the build system cannot know about them. Instead, try adding it in the scripts array. That will ensure it will get bundled and loaded correctly.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants