Jquery TypeScript和JQ插件(Angular4)

Jquery TypeScript和JQ插件(Angular4),jquery,angular,typescript,jquery-plugins,Jquery,Angular,Typescript,Jquery Plugins,我尝试在Angular 4项目的组件中使用JQ插件。 这是我的密码 import { Component, OnInit } from '@angular/core'; import * as $ from "../../../node_modules/jquery/dist/jquery.min.js"; import "../../../node_modules/materialize-css/dist/js/materialize.min.js"; @Component({ selec

我尝试在Angular 4项目的组件中使用JQ插件。 这是我的密码

import { Component, OnInit } from '@angular/core';
import * as $ from "../../../node_modules/jquery/dist/jquery.min.js";
import "../../../node_modules/materialize-css/dist/js/materialize.min.js";

@Component({
 selector: 'app-table',
 templateUrl: './table.component.html',
 styleUrls: ['./table.component.css']
})
export class TableComponent implements OnInit {

 constructor() { }

 ngOnInit() {

  $(document).ready(function() {
     $('select').material_select();
    });
}

}
“材料选择”是插件中的一个函数。 但在我的控制台中,我看到下一个:

我想我不明白如何在这里导入jq插件。 我如何才能做到这一点?

尝试以下步骤

  • npm安装--save@types/jquery

  • declare var$:JQueryStatic类之前的代码中添加code>,然后可以像以前一样使用jquery

  • 扩展jquery接口

    interface JQueryEx extend JQuery {
      material_select(): any;
    }
    
  • ($('select')作为JQueryEx.material\u select()
    添加到
    ngAfterViewInit()
    函数中,并从
    ngOnInit()
    中删除代码