javascript – 错误:_. get不是函数

我正在尝试将angular-timezone-selector [on Github]实施到我现有的角度项目中.

我创建了一个解耦的working plunker here

当我尝试将其实现到我的项目中时,我收到以下错误:

错误:_. get不是函数

这些是我的依赖:

var app = angular.module('app',
  [
    'ngSanitize',
    'ui.router',
    'ui.bootstrap',
    'pascalprecht.translate',
    'tmh.dynamicLocale',
    'ngCookies',
    'angular-loading-bar',
    'google.places',
    'LocalStorageModule',
    'angular-timezone-selector'
  ]
);

这是我加载到我的html:

  <!-- jQuery first -->
  <script src="assets/bower_components/jquery/dist/jquery.min.js"></script>
  <script src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
  <script src="assets/bower_components/moment/moment.js"></script>
  <script src="assets/bower_components/moment-timezone/builds/moment-timezone-with-data.js"></script>
  <script src="assets/bower_components/chosen/chosen.jquery.min.js"></script>
  <script src="assets/bower_components/lodash/lodash.min.js"></script>

  <!-- Angular specific scripts -->
  <script src="assets/bower_components/angular/angular.js"></script>
  <script src="assets/bower_components/angular-cookies/angular-cookies.js"></script>
  <script src="assets/bower_components/angular-sanitize/angular-sanitize.js"></script>
  <script src="assets/bower_components/underscore/underscore.js"></script>
  <script src="assets/bower_components/angular-resource/angular-resource.js"></script>
  <script src="assets/bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
  <script src="assets/bower_components/angular-ui-router/release/angular-ui-router.js"></script>
  <script src="assets/bower_components/angular-ui-bootstrap-bower/ui-bootstrap-tpls.js"></script>
  <script src="assets/bower_components/angular-translate/angular-translate.js"></script>
  <script src="assets/bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
  <script src="assets/bower_components/angular-dynamic-locale/dist/tmhDynamicLocale.js"></script>
  <script src="assets/bower_components/angular-loading-bar/build/loading-bar.js"></script>
  <script src="assets/bower_components/angular-google-places-autocomplete/src/autocomplete.js"></script>
  <script src="assets/bower_components/angular-timezone-selector/angular-timezone-selector.js"></script>
  <script src="scripts/app.js"></script>

...

这是我的bower.json文件的一部分,它提供了我的资产:

...
    "moment": "2.11.1",
    "moment-timezone": "0.5.0",
    "chosen": "1.4.2",
    "lodash": "3.9.3",
    "angular-timezone-selector": "1.4.3"
...

也许这是一个lodash错误.我该如何解决这个问题?

解决方法:

  angular.module('lodash', []).factory('_', ['$window', function ($window) {
    return $window._;
  }]);

  angular.module('yourApp', [
    // angular
    'ngAnimate',
    'ngCookies',
    // angular ui
    'ui.router',
    'ui.bootstrap',
    'ui.validate',
    // third party
     'angular-loading-bar',
    'lodash'
  ]);

然后将其注入您的服务或控制器.

上一篇:javascript – 如何按键对对象数组进行分组


下一篇:javascript – 将数组转换为不同的类型(lodash / js)