gridstack.js icon indicating copy to clipboard operation
gridstack.js copied to clipboard

ERROR TypeError: $(...).gridstack is not a function

Open orbitboy007 opened this issue 9 years ago • 3 comments

I am trying to use gridstack with angular2 i am using all possible way but this error not gone. can any one help me to figure it out??

ERROR TypeError: $(...).gridstack is not a function at my-grid-stack.component.ts:23 at ZoneDelegate.webpackJsonp.627.ZoneDelegate.invokeTask (zone.js:398) at Object.onInvokeTask (core.es5.js:4116) at ZoneDelegate.webpackJsonp.627.ZoneDelegate.invokeTask (zone.js:397) at Zone.webpackJsonp.627.Zone.runTask (zone.js:165) at ZoneTask.invoke (zone.js:460) at timer (zone.js:1540)

Index.html file contain :

orbitboy007 avatar May 26 '17 11:05 orbitboy007

Hi, @orbitboy007 . You should use the gridstack.js and gridstack.jQueryUI.js files in CDN rather than the ones you listed. That won't fix your problem, but is still necessary.

I don't have experience with angular, but if you could provide a jsfiddle we can try to help you diagnose the issue.

radiolips avatar May 28 '17 16:05 radiolips

I've managed to get it working with webpack and angular 2. To do this, in the webpack.config.vendor.js file, I put:

'gridstack/dist/gridstack.min.css',
'gridstack',
'jquery',
'jquery-ui',
'lodash',

In package.json, your lodash version will need to be "3.5.0"

In your webpack.config.js file, you need to add an alias to the jquery-ui objects that were moved into a "ui" folder. This is because jquery-ui moved the location, but gridstack didn't keep up.

My resolve statement in webpack.config.js looks like this:

resolve: {
            extensions: ['.ts', '.js'],
            'alias': {
                'jquery-ui': 'jquery-ui/ui'
            },
        },

You will also need npm packages. In the package.json file, in the dependencies section, you'll need

"gridstack": "0.3.0",
"jquery": "3.2.1",
"jquery-ui": "1.12.1",
"lodash": "3.5.0",

and in the devDependencies section, you'll need typings files

"@types/gridstack": "0.0.38",
"@types/jquery": "3.2.11",
"@types/jqueryui": "1.11.36",
"@types/lodash": "4.14.74",

Don't worry about about the typings version numbering being out of sync - it still works.

Where needed, you can import the gridstack components using:

import 'gridstack';
import 'gridstack/dist/gridstack.jQueryUI';

anthwri avatar Aug 31 '17 04:08 anthwri

import 'gridstack' work for me! @tonywr71

yangxiaolin avatar Jan 12 '18 07:01 yangxiaolin