Reputation: 540
I am trying to use this https://github.com/ShinDarth/Nestable jquery plugin for nested drag and drop feature. I have already installed the jquery from npm install jquery --save
and typings from npm install @types/jquery --save-dev
i have declared import * as $ from 'jquery';
in my component and included the plugin file in index.html
page.
Here is my component code:
import { Component, OnInit,AfterViewInit,ElementRef } from '@angular/core';
import { MdDialog, MdDialogRef } from "@angular/material";
import { MediaUploadComponent } from '../helper-component/media-upload/media-upload.component';
import * as $ from 'jquery';
// import 'jquery';
// declare const $: JQueryStatic;
// declare var $:any;
// import $ from "jquery";
@Component({
selector: 'app-appearance',
templateUrl: './appearance.component.html',
styleUrls: ['./appearance.component.css']
})
export class AppearanceComponent implements OnInit ,AfterViewInit{
private selectedOption:string ;
site_icon:any;
constructor() { }
ngOnInit() {
}
ngAfterViewInit(){
// jquery plugin nestable
$('.nestable').nestable();
//console.log(jQuery.fn.jquery);
}
}
How can i fix this problem?
[i have already tried including the jquery link to index page from the cdn but shows the same error]
Index.html
!doctype html>
<html>
<head>
<meta charset="utf-8">
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<link rel="stylesheet" href="../assets/bootstrap.min.css">
<!--<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> -->
<script src="../assets/nestable/jquery.nestable.js"></script>
<script src="../assets/nestable/jquery.nestable++.js"></script>
</head>
....
Upvotes: 0
Views: 4242
Reputation: 17327
Ultimately you'd want to install jquery
and other libraries in the angular-cli.json
scripts: [
"../node_modules/jquery/dist/jquery.min.js",
"../assets/nestable/jquery.nestable.js",
"../assets/nestable/jquery.nestable++.js"
]
The changes will only apply once you restart ng serve
.
EDIT: For further reading and explanation this article might be of help https://github.com/angular/angular-cli/wiki/stories-global-scripts
Upvotes: 7