我正在尝试使用lodash ng-repeat以这种方式在指令中使用它:
ng-repeat
<div ng-controller="GridController" ng-repeat="n in _.range(5)"> <div>Hello {{n}}</div> </div>
存在GridController:
GridController
IndexModule.controller('GridController', function () { this._ = _ })
但是不起作用,因此,没有任何 重复 。如果我将指令更改为ng-repeat="i in [1,2,3,4,5]"它将起作用。
ng-repeat="i in [1,2,3,4,5]"
lodash 通过已经包含<script>在<header>之前 angular 。我该如何运作?
lodash
<script>
<header>
angular
我更喜欢在全局范围内引入“ _”并且可以注入以进行测试。
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._; });