我在使用AngularJS时使用underscore.strings时遇到了麻烦。
围绕underscore.strings的文档总是显示带有requireJs的示例,我认为这些示例不适用于AngularJS。
我无法使用这些参数中的任何一个来访问字符串函数,我对如何初始化没有requirejs的underscore.strings感到有点困惑
<script src="/bower_components/underscore/underscore.js"></script>
<script src="/bower_components/underscore.string/dist/underscore.string.js"></script>
<script type="text/javascript">
$(document).ready(function() {
try {
console.log(_); // Returns a reference to Underscore
} catch (e) {
console.log(e);
}
try {
console.log(_s); // Undefined
} catch (e) {
console.log(e);
}
try {
console.log(_.str); // Undefined
} catch (e) {
console.log(e);
}
try {
console.log(_.string); // Undefined
} catch (e) {
console.log(e);
}
});
</script>
答案 0 :(得分:1)
尝试使用 s 访问underscore.string全局。
使用_.mixin(s.exports());
答案 1 :(得分:0)
尝试使用:
https://github.com/floydsoft/angular-underscore
此模块将下划线的API暴露在角度应用程序的根范围内, 并从下划线提供一些过滤器。
与以下内容结合使用: