Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to include jquery plugins in angular 2 version #2802


User avatar
0
malomatia created

i have created angular 2 +asp.net core project, and created a new NG2 component, i'm trying to include one of metronic jquery components in the NG2 component with no luck, i have done the following:

  • added the component through npm: npm install easy-pie-chart --save
  • in the component.ts added: import * as $ from 'jquery'; import 'easy-pie-chart';
  • inside ngAfterViewInit added: $('.easy-pie-chart .number.transactions').easyPieChart({ animate: 1000, size: 75, lineWidth: 3, barColor: App.getBrandColor('yellow') });

im getting many errors and unable to complete it at all, please help


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Can you share the screenshot of errors ?

    Thanks.

  • User Avatar
    0
    malomatia created

    after adding "declare var $: any" to the .ts file to bypass typescript, i'm getting the below error:

    <a class="postlink" href="https://www.dropbox.com/s/gnwlymjvqbsgd9o/Capture.JPG?dl=0">https://www.dropbox.com/s/gnwlymjvqbsgd ... e.JPG?dl=0</a>

    please help

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Have you added easy-pie-chart script to angular-cli.json ?

  • User Avatar
    0
    malomatia created

    Yes, i have added it under "scripts": section like this:

    "../src/assets/plugins/jquery-easypiechart/jquery.easypiechart.js",

    and still getting the same error.

    please help.

  • User Avatar
    0
    malomatia created

    is there a some guide how to include metronic components (since most of it is based on jquery) or any jquery components in general in aspnet zero client project ? i see there is many coomponents are already used like jTable but can't find out the steps to do that.

  • User Avatar
    0
    malomatia created

    problem solved after killing the NG process in terminal and running npm start again.

    Thank you very much, however there are some questions arised now:

    • is it required to use "declare var $: any" or no ? i noticed after commenting it the application still works, even TS is compiling normally

    • adding the file manually to .angular-cli.json is the way when the plugin is not available on NPM catalog, right ?

    Thank you again, your support is highly appreciated.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @malomatia,

    I think "declare var $: any" is not necessary. We declare such typings in this file <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/angular/src/typings.d.ts">https://github.com/aspnetzero/aspnet-ze ... pings.d.ts</a> for the libraries which don't have typing files.

    For example we defined slimscroll typing like this

    interface JQuery {
        slimScroll(...any): any;
    }
    

    Yes, you need to include script paths to .angular-cli.json even if they exist in npm.

  • User Avatar
    0
    malomatia created

    Thanks a lot (Y)

  • User Avatar
    0
    ismcagdas created
    Support Team

    You are welcome :)