angular.module('demo', []).controller('ctrl' ,['$scope', 'underscoreService', function ($scope, underscoreService){
$scope.list = ['Mercury', 'Venus', 'Earth', 'Mars',
'Jupiter', 'Saturn', 'Uranus',
'Neptune', 'Pluto'];
$scope.sampleList = underscoreService.sample($scope.list, 3);
$scope.shuffleList = underscoreService.shuffle($scope.list);
}]).factory('underscoreService', function(){
return _;
}).config(['$provide', function($provide){
// override the function. you can uncomment it if you just want it to shuffle
$provide.decorator('underscoreService', function($delegate){
$delegate.shuffle = function(list){return list};
return $delegate;
});
}]).config(function(){
// second config doesn't break angular!
console.log("HERE");
});
<div ng-controller='ctrl'>
<h2>List</h2>
<ol>
<li ng-repeat='item in list'>
{{item}}
</li>
</ol>
<h2>Sample List</h2>
<ol>
<li ng-repeat='item in sampleList'>
{{item}}
</li>
</ol>
<h2>Shuffle List</h2>
<ol>
<li ng-repeat='item in shuffleList'>
{{item}}
</li>
</ol>
</div>