【问题标题】:How to add underscore module to MeanJS?如何将下划线模块添加到 MeanJS?
【发布时间】:2016-12-07 09:56:29
【问题描述】:

好的,首先我从凉亭安装它:

bower install angular-underscore-module

然后在 modules/core/clients/app/config.js 的第 7 行添加了注入:

  var applicationModuleVendorDependencies = ['ngResource', 'ngAnimate', 'ngMessages', 'ui.router', 'ui.bootstrap', 'ui.utils', 'angularFileUpload', 'underscore'];

要将其注入我的控制器,在 modules/articles/client/controllers/articles.client.controller.js 我是这样添加的:

angular.module('articles').controller('ArticlesController', ['$scope', '$stateParams', '$location', 'Authentication', 'Articles', '_',
  function ($scope, $stateParams, $location, Authentication, Articles, _) {

然后,我得到了这个错误:

angular.js:13920 Error: [$injector:undef] Provider '_' must return a value from $get factory method.

那么在这篇文章中: Provider 'xx' must return a value from $get factory method in AngularJs

它说,我应该在 return 前面插入 { 而不是在下一行,但是,我找不到那个 return。我在这里做错了吗?请建议。谢谢。

【问题讨论】:

    标签: javascript angularjs underscore.js meanjs


    【解决方案1】:

    找到了!

    在您的 config/assets/default.js、client.lib.js 中,您必须同时包含 underscore.min.js 和 angular-underscore-module.js,如下代码:

    [...]
        'public/lib/underscore/underscore-min.js',
        'public/lib/angular-underscore-module/angular-underscore-module.js',
    [...]
    

    【讨论】:

      【解决方案2】:

      下划线将自身附加到窗口对象。您不需要在控制器中包含依赖项。但是,如果您仍想使用“_”,则可以执行以下操作:

      app = angular.module('MyApp', ['underscore']);
      app.factory('_', ['$window', function($window) {
        return $window._;
      });
      

      那么您可以在控制器中包含“_”作为依赖项。

      【讨论】:

      • 谢谢,但问题是关于meanjs,而不是角度服务。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 2018-05-19
      • 2013-02-21
      • 1970-01-01
      • 2017-03-17
      • 1970-01-01
      相关资源
      最近更新 更多