javascript - How can I use jQuery in CatberryJS application? -


i want use jquery in web application on catberryjs framework. how can it?

using jquery library registered globally

you can use jquery usual, include script tag "head" component:

<script src="//code.jquery.com/jquery-2.1.3.min.js"></script> 

and feel free use jquery functions in component's code except constructor , "render" method.

using jquery part of built bundle.js

in case can install jquery using npm this:

npm install jquery --save 

then register jquery catberry service in ./browser.js

var catberry = require('catberry'),     cat = catberry.create({/* config */}),     jquery = require('jquery');  cat.locator.registerinstance('jquery', jquery); 

after jquery registered, can use in components resolving catberry service locator:

var $ = this.$context.locator.resolve('jquery'); $('.class').html('<div>hello, world!</div>'); 

additionally

if use jquery functions in component's constructor or component's "render" method should check environment flag this:

if (this.$context.isbrowser) {   // crazy jquery stuff } 

also, keep in mind avoid memory leaks component should unsubscribe jquery events , free resources used jquery functions in "unbind" method.

you can use browser-side library inside component it's described above jquery.