我正在尝试使用 lodash 使用它ng-repeat
指令,以这种方式:
<div ng-controller="GridController" ng-repeat="n in _.range(5)">
<div>Hello {{n}}</div>
</div>
Being GridController
:
IndexModule.controller('GridController', function () {
this._ = _
})
然而不起作用,所以什么也没有repeated。如果我将指令更改为ng-repeat="i in [1,2,3,4,5]"
它会起作用的。
lodash
已经包含在<script>
at <header>
before angular
。我怎样才能让它发挥作用?
我更喜欢在全局范围内引入“_”并可注入进行测试,请参阅我对此问题的回答在控制器内使用下划线 https://stackoverflow.com/questions/14968297/use-underscore-inside-controllers/23984685#23984685
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._;
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)