2016-08-02 132 views
0

好的,第一I從亭子安裝這樣的:在模塊如何將下劃線模塊添加到MeanJS?

bower install angular-underscore-module 

接着/核心/客戶端/應用程序/ config.js中,管線7 I加入注射:

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

爲了注射它在我的控制器,模塊/條/客戶/控制器/ 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

它說,我應該插入{回報的前面,而不是在下一行,但是,我無法找到的回報。我在這裏做錯了什麼?請建議。謝謝。

回答

1

下劃線附加到窗口對象。您不需要在控制器中包含依賴項。但是如果你仍然想使用「_」你可以做這樣的事情:

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

那麼你可以包括「_」作爲你的控制器的依賴。

+0

謝謝你,但問題是關於meanjs,而不是角度服務。 – Vicheanak

0

找到了!

在你的config /資產/ default.js的client.lib.js,你必須包括underscore.min.js和角下劃線module.js如下代碼:

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