如何使角JS lodash工作? [英] How to make lodash work with Angular JS?
问题描述
我试图用lodash在 NG-重复使用
指令,是这样的:
I'm trying to use lodash use it at ng-repeat
directives, in this way:
<div ng-controller="GridController" ng-repeat="n in _.range(5)">
<div>Hello {{n}}</div>
</div>
存在 GridController
:
IndexModule.controller('GridController', function () {
this._ = _
})
但不工作,因此,没有什么是的重复的。如果我改变了指令 NG-重复=我在[1,2,3,4,5]
它会工作。
However is not working and so, nothing being repeated. If I change the directive to ng-repeat="i in [1,2,3,4,5]"
it'll work.
lodash
通过已经包括&LT;脚本&GT;
在&LT;报头GT;
之前的 角
。我怎样才能使它工作?
lodash
is already included via <script>
at <header>
before angular
. How can I make it work?
推荐答案
我preFER引进'_'全球和注射做检查,看看我回答这个问题
<一href=\"https://stackoverflow.com/questions/14968297/use-underscore-inside-controllers/23984685#23984685\">Use强调内部控制器
I prefer to introduce '_' globally and injectable for tests, see my answer to this question Use underscore inside controllers
var myapp = angular.module('myApp', [])
// allow DI for use in controllers, unit tests
.constant('_', window._)
// use in views, ng-repeat="x in _.range(3)"
.run(function ($rootScope) {
$rootScope._ = window._;
});
这篇关于如何使角JS lodash工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!