I am using bootstrap in my react app generated with create-react-app
Below are two imports that I am using in my index.html
<script src="./vendor/jquery-3.1.0.min.js"></script>
<script src="./vendor/bootstrap.min.js"></script>
However in code when I use something like
$('.dropdown').dropdown()
I get an error as - error '$' is not defined no-undef
Can someone help me with this. Thanks!
If you need jQuery, run:
npm install --save jquery
Then you can use it in the app code:
import $ from 'jquery';
Note that this only works with versions 2.x and above.
You can also use it as a script tag.
This is not encouraged.
To do it, put jQuery into the public folder and add this to HTML:
<script src="%PUBLIC_URL%/jquery-3.1.0.min.js"></script>
Then you can use it from the app:
const $ = window.$;
In general I would recommend trying React Bootstrap instead of Bootstrap in React projects. It provides similar looking components but doesn't need jQuery and works on top of React.
I hope this helps! Please file issues if you're confused about something. We are happy to help.
You might need to require the jquery package. Include var $ = require ('jquery') (after installing it -- npm install --save jquery) on all the components that reference jQuery.
Related
I can't seem to find a way on how to use bootstrap locally in react without npm or yarn bootstrap installation or even without CDN, every tutorial I find on how to use bootstrap they don't explain using bootstrap locally.
Please I need steps on how I can achieve this thanks
So I don't know this for sure, so please correct me if I am wrong. I am just trying to help you to the best of my knowledge.
There are multiple ways.
The first way is to import the CSS in the app.js (or the start of the React app). For the CSS you should have a file called bootstrap.css that contains all the CSS for Bootstrap. import './bootstrap.css'.
The second way is to import it in the html file. If you add the the <link rel="stylesheet" type="text/css" href="bootstrap.css">.
I don't know if this is the way it should be done!
I'm using ghcjs-0.2.0.9006030_ghc-7.10.3 with stack lts-6.30 to build a frontend app. Inspired by this post, I decided to use react-flux and material-ui. I added React's CDN link to my index.html, and configured GHCJSi to use a custom index-dev.html when working with the repl.(React's CDN link is also included in index-dev.html)
However, with material-ui-next, the official installation method is to use NPM. They provide no CDN link. So how to use this library in a GHCJS project? I think one of the following should work:
Use the CDN link provided by jsDelivr. (Though this link doesn't work)
Find some way to bundle material-ui-next and put it in js-sources field in cabal, so that it can be linked with our app at build time.
Any help is appreciated.
In the package.json of material-ui, scripts build:umd:prod and build:umd:dev can be used to build UMD bundles of the package. So you can use the CDN link provided by unpkg.
Even though material-ui doesn't declare a peer dependency on react-transition-group, it expects react-transition-group/TransitionGroup to be present. So we have to add the following code before the link to material-ui
<script crossorigin="anonymous" src="https://unpkg.com/react-transition-group#2.2.1/dist/react-transition-group.js"></script>
<script>
window["react-transition-group/TransitionGroup"] = ReactTransitionGroup.TransitionGroup;
</script>
I created a issue on material-ui's github repository, see that issue for more details.
This should be straight forward, but I'm stuck.
I'm trying to include mobile-angular-ui in an angular-fullstack-generator project but I keep getting
Uncaught SyntaxError: Unexpected token < mobile-angular-ui.min.js:1
I'm adding the following at the end of the body of the _index.html, and the network tab is returning the proper 200 response.
<script src="/node_modules/mobile-angular-ui/dist/js/mobile-angular-ui.min.js"></script>
If I use import in app.js like this
import mobileUi from '../../node_modules/mobile-angular-ui/dist/js/mobile-angular-ui.js';
Then I get the following error
Uncaught TypeError: Cannot read property 'documentElement' of undefined mobile-angular-ui.js:2584
Where am I going wrong, where am I supposed to include this?
Thanks!
Normally, with the angular-fullstack app from https://github.com/angular-fullstack/generator-angular-fullstack,
you just have to write:
npm install --save mobile-angular-ui angular angular-route
And all the dependencies will automatically be built.
In angular-fullstack, all front end libraries are handled/installed through bower and all back end libraries are handled through npm.
So if you want to use mobile-angular-ui, which is a front end library, you should try installing it like this.
bower install --save mobile-angular-ui angular angular-route
Then add the module dependency
mobile-angular-ui
in app.js of client side Then serve the project again. Now your dependency will be added automatically in your index.html file and you won't need to automatically include it in your index.html
I am making use of yeoman angular fullstack generator
i want to install admin-lte-angular theme in my app
i have installed it using bower
but i don't know how install it in angular app
please help to install it
Add the css and the javascript libs to the index.html:
<link href="bower_components/admin-lte-angular/admin-lte-angular.css">
// angular.js must be loaded first!
<script src="bower_components/admin-lte-angular/admin-lte-angular.js"></script>
Add 'admin-lte-angular' to the module dependencies:
angular.module('dashboardApp', [ 'admin-lte-angular' ])
If you are using this https://github.com/sarahhenderson/admin-lte-angular
Note that the author stated it is a working in progress. So I don't think it is a stable code to use.
I would like to know how to solve this issue which Meteor (v0.5.7) with Meteor_angularjs(v1.2.0) generates 'html##html_attributes##' tag within body tag.
If I use Meteor(v0.5.6) with Meteor_angularjs(v1.2.0), this issue doesn't happen.
So I think some generating code in Meteor(v0.5.7) has affected Meteor_angularjs.
This case is like this:
<html>
<head>…</head>
<body>
<html##html_attributes##>
<script type="text/javascript" src="/packages/underscore/underscore.js?47479149fe12fc56685a9de90c5a9903390cb451"></script>
...
(generated code by Meteor)
...
</html##html_attributes##>
</body>
</html>
You can see this issue with todos from Meteor_angularjs (v1.2.0) with Meteor (v0.5.7).
Avoiding this issue, I'm using Meteor (v0.5.6) currently for testing an integration of Meteor and Angular.
The way to fix this is to run it with meteorite. Using Meteor always causes these issues for me. Here's how to fix:
Install meteorite: sudo npm install -g meteorite
CD into your directory:
cd myproject
Now, instead of running meteor, run mrt for
everything! Add the package: mrt add angularjs will automatically
download and add the package.
Now, run your project with meteorite:
mrt
That should fix your problem.