0

I'm having trouble getting underscore.strings working with AngularJS.

The documentation around underscore.strings always shows examples with requireJs which I don't think is appropriate for AngularJS.

I can't access the string functions with any of these statments, I'm a little confused on how I'm supposed to initialize underscore.strings without requirejs

<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>

2 Answers 2

1

Try using s to access the underscore.string global. Integrate into underscore with _.mixin(s.exports());

Sign up to request clarification or add additional context in comments.

Comments

0

Try using this:

https://github.com/floydsoft/angular-underscore

This module exposes underscore's API into angular app's root scope, and provides some filters from underscore.

Use it in conjunction with:

https://github.com/epeli/underscore.string

2 Comments

Can you give some clarity around how you use it with underscore.string? I've already been able to get undescore.js working fine, I've also used this angular-underscore connector github.com/andresesfm/angular-underscore-module. I don't really get how the example you've allows me to use underscore.string?
Worked it out, DCMarkie answer was what I was looking for

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.