Webpack: how to make angular auto-detect jQuery and use it as angular.element instead of jqLite?

前端 未结 5 1109
甜味超标
甜味超标 2021-01-31 14:42

I\'m using Webpack to build an Angular 1.4 project. The project makes use of several jQuery plugins, which are wrapped into angular directives. Those directives internally use <

5条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-31 15:32

    !!Update

    Apparently you still need to use the commonJs require for angular in the ES6 example.

    import $ from "jquery"
    
    window.$ = $;
    window.jQuery = $;
    
    var angular = require("angular");
    

    below is the original answer



    I want to purpose a easier solution. Just make jQuery a window global so that angular can recognize it:

    var $ = require("jquery")
    
    window.$ = $;
    window.jQuery = $;
    
    var angular = require("angular");
    

    or in your case (OUT DATED):

    import $ from "jquery"
    
    window.$ = $;
    window.jQuery = $;
    
    import angular from "angular";
    

    I hope this helps :)

提交回复
热议问题