Open ralyodio opened 10 years ago
Yes, but how to use ?
I ended up just doing this:
.run(function ($rootScope, $location, Auth) {
//expose lodash to templates
$rootScope._ = _;
});
});
Another way:
var underscore = angular.module('underscore', []);
underscore.factory('_', function() {
return window._;
});
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, _) {
});
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.
@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
});
@jarcoal PR is welcome!
Thanks @floydsoft, i will check later!
How do I load this thing into my controller so I get
_
?