【发布时间】:2014-11-21 11:45:33
【问题描述】:
问题很简单,如何在AngularJS项目中成功实现Lodash和underscore.string库?
有必要使用RequireJS来实现吗?
【问题讨论】:
标签: angularjs lodash underscore.string.js
问题很简单,如何在AngularJS项目中成功实现Lodash和underscore.string库?
有必要使用RequireJS来实现吗?
【问题讨论】:
标签: angularjs lodash underscore.string.js
【讨论】:
感谢@sylwester 的回复我想通了,但他的回答只是一个提示,所以我决定再丰富一点。
不,您不需要使用 RequireJS 将这两个库一起实现到 AngularJS 项目中。但是很容易实现——看看这个article。
然后将underscore.string下载到你的项目中:
$ bower install underscore.string --save-dev
最后确保将库添加到您的index.html:
<script type="text/javascript" src="vendor/loadash/lodash.js"></script>
<script type="text/javascript" src="vendor/angular/angular.js"></script>
<script type="text/javascript" src="vendor/angular-loadash/angular-loadash.js"></script>
<script type="text/javascript" src="vendor/underscore.string/underscore.string.js">
请随意使用 RequireJS 改进此答案。
【讨论】:
创建此服务,现在您可以在 underscore.js 中使用 underscore.string
类似:_.capitalize('hello') --> 'Hello'
angular.module('underscore', []).factory('_', ['$window', function($window) {
$window._.mixin(s.exports());
return $window._;
}]);
【讨论】: