Skip to content
This repository has been archived by the owner on Jan 27, 2024. It is now read-only.

load into controller? #14

Open
ralyodio opened this issue Jun 5, 2014 · 9 comments
Open

load into controller? #14

ralyodio opened this issue Jun 5, 2014 · 9 comments
Labels

Comments

@ralyodio
Copy link

ralyodio commented Jun 5, 2014

How do I load this thing into my controller so I get _?

@floydwch
Copy link
Owner

floydwch commented Jun 5, 2014

@sandrocsimas
Copy link

Yes, but how to use ?

@ralyodio
Copy link
Author

I ended up just doing this:

    .run(function ($rootScope, $location, Auth) {

        //expose lodash to templates
        $rootScope._ = _;

        });
    });

@sandrocsimas
Copy link

Another way:

var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
    return window._;
});  

@screendriver
Copy link

Can this be done in the angular-underscore library? I would like to use it like so:

angular.module('myApp', ['angular-underscore'])
.controller('MyCtrl', function($scope, _) {

});

@jarcoal
Copy link

jarcoal commented Sep 12, 2014

It does seem a little silly that you can't just have underscore injected into a controller.

@floydsoft would it be reasonable to add in something like this:

.constant('_', _)

I could submit a PR if you'd accept it.

@floydwch
Copy link
Owner

@chovy @sandro-csimas @screendriver : Oops, I finally found that I forgot adding document of how to access the underscore utilities from controller, in the current version, the utilities is bound on the $rootScope which means we can access the functions of underscore by $scope such as:

angular.module('myApp', ['angular-underscore'])
.controller('MyCtrl', function($scope) {
    $scope.sample([1, 2, 3]); // got 1, or 2, or 3.
    $scope._([1, 2, 3]); // underscore's chain, http://underscorejs.org/#chain
});

@floydwch
Copy link
Owner

@jarcoal PR is welcome!

@sandrocsimas
Copy link

Thanks @floydsoft, i will check later!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants