如何使用带有@ types / jstree的typescript将jstree添加到angular 2应用程序

前端之家收集整理的这篇文章主要介绍了如何使用带有@ types / jstree的typescript将jstree添加到angular 2应用程序前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
嗨,我相信这是一个新问题,但我是ng2的新手所以请耐心等待…

我弄完了:

npm i jstree --save

在我创建使用angular-cli应用程序之后.

然后我安装:

npm i @types/jstree --save-dev

这是在设置,然后我试图使用它,没有运气.

请有人可以告诉我如何使用带有打字稿的第三方库

解决方法

以下是我采取的步骤.
我从一个新的cli应用程序开始.

npm install –save jquery jstree

npm install –save-dev @ types / jquery @ types / jstree

然后我更新了angular.json文件,如果您使用的是旧版本的angular-cli,则会更改angular-cli.json文件.我将“../node_modules/jstree/dist/themes/default-dark/style.min.css”添加到styles属性数组中.

我还在scripts属性数组中添加了两个项目:

“../node_modules/jquery/dist/jquery.min.js”
“../node_modules/jstree/dist/jstree.min.js”

然后我将src / app / app.component.html更新为

<div id="foo">
  <ul>
    <li>Root node 1
      <ul>
        <li>Child node 1</li>
        <li><a href="#">Child node 2</a></li>
      </ul>
    </li>
  </ul>
</div>

我还将src / app / app.component.ts更新为

import { Component,OnInit } from '@angular/core';

declare var $: any;

@Component({
  selector: 'app-root',templateUrl: './app.component.html',styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
  ngOnInit(): void {
    $('#foo').jstree();
  }
}

希望这可以帮助!

猜你在找的Angularjs相关文章