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

$(...) pivot is not a function in jquery + angular 4 + webpack Compiled successfully #884

Closed
vaibhav2018 opened this issue Mar 15, 2018 · 8 comments

Comments

@vaibhav2018
Copy link

index.html

indexhtml

pivot.component.html

pivotcomponenthtml

pivot.component.ts

pivotcomponentts

angular-cli.json

angular-clijson

package.json

packagejson

webpack compiled successfully

webpack compiled successfully

localhost:4200/pivot

localhost 4200

app.component.ts

import { Component } from '@angular/core';
import * as $ from 'jquery';
@component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}

app.component.html

appcomponenthtml

I was able to follow some steps to achieve this but still getting error.
Not sure how it can be solved.
Please help guys.

@nicolaskruchten
Copy link
Owner

Posting screenshots of code makes it almost impossible to help you. Can you post a minimal repo or something so that someone can try to execute the code you're wanting help with?

@FloPrey
Copy link

FloPrey commented Mar 15, 2018

We had a similar issue and we had to set jquery to global scope in webpack.

We added this to the config.modules:
{ test: require.resolve('jquery'), loader: 'expose-loader?jQuery' }

Also we imported jquery different:
import jQuery from 'jquery';
and than
const pivotElement = jQuery(element[0]);
pivotElement.pivotUI();

@Arezoo-Bozorgmehr
Copy link

Hey guys,

i am not professional in Angular, but I have a project in angular and need in this case a pivot table. This module unfortionattly is for angularjs and i`m working with angular 4. Could you help me please, how can I make this for my ptoject.

@FloPrey
Copy link

FloPrey commented Mar 18, 2018

Hi,

actually this project just uses jquery and not angularjs.
So for using it, you have to import jquery and jquery-ui and the pivot table should work no matter if you use angularjs or angular 4.

@vaibhav2018
Copy link
Author

@FloPrey already imported jquery and jquery-ui
@Arezoo-Bozorgmehr this is working in angular 4 also just some proper setup needed
As of now working
Steps:

  1. removed import * as $ from jquery from pivot.component
  2. added declare var $ : any in pivot.component
  3. if you are using any google charts, d3, make sure it is available in angular-cli.json in scripts
    "scripts": [
    "../node_modules/jquery/dist/jquery.min.js",
    "../node_modules/jquery-ui-dist/jquery-ui.js",
    "../node_modules/pivottable/dist/pivot.min.js",
    "../node_modules/pivottable/dist/d3_renderers.min.js",
    "../node_modules/pivottable/dist/gchart_renderers.min.js"
    ]
  4. added import 'jquery-ui'; in pivot.component

@vaibhav2018
Copy link
Author

should we close this issue?

@nicolaskruchten
Copy link
Owner

If your needs are met yes we can close this issue. Note that there is a long discussion of Angular integration here: #208

@abdelwahebmoalla
Copy link

@vaibhav2018
I added "../node_modules/pivottable/dist/gchart_renderers.min.js" and I added
script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> in index.html
but I still get TypeError: Cannot read property 'arrayToDataTable' of undefined when I choose line chart
what am i missing or doing wrong ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants