AngularJS 2应用程序中的全球负载jQuery



我需要在我的应用程序的所有组件中使用jQuery,以便我可以像这样使用

导入jquery;并在所有组件中使用jQuery API

我正在使用SystemJS,Angular 2和打字稿。我该如何实现?

问候

您需要在应用程序中导入jQuery $,并且必须配置Systemjs Loader,其中jQuery库将可用

    //in your typescript angular2
    import * as $ from 'jQuery';
    // in your systemjs configuration
    //map
    (function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        'app', // 'dist',
    'jQuery':                     'node_modules/jQuery/lib/node-jquery.js',
  };

您也可以在html index.html中导入它,如下

System.import('jQuery').catch(function(err){ console.error(err); });

调整自我以使其起作用

最新更新