inject jquery and underscore to angular js component

前端 未结 1 537
野性不改
野性不改 2021-02-08 17:01

I am using angularjs, underscore and jQuery in my new service:

myModule.factory(\'MyService\', [\'MyResource\', function (MyResource) {
     ....
    // Here          


        
1条回答
  •  深忆病人
    2021-02-08 17:29

    based on @moderndegree's approach I have implemented the following code, I cannot say it is perfect but this way tester would know if it has jQuery dependency as $window is too generic object to inject.

    'use strict';
    (function () {
        var app= angular.module('app');
        //these are just references the instance of related lib so we can inject them to the controllers/services in an angular way.
        app.factory('jQuery', [
            '$window',
            function ($window) {
                return $window.jQuery;
            }
        ]);
    
        app.factory('Modernizr', [
            '$window',
            function ($window) {
                return $window.Modernizr;
            }
        ]);
    
        app.factory('Highcharts', [
        '$window',
        function ($window) {
            return $window.Highcharts;
        }
        ]);
    
    })();
    

    0 讨论(0)
提交回复
热议问题