Created
January 28, 2016 10:42
-
-
Save JonCatmull/b235151aabccc641599d to your computer and use it in GitHub Desktop.
Angular filter - Move an array item to first position but preserve the rest of the lists order (only set up for basic array of either integers or strings)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
'use strict'; | |
angular | |
.module('fcp') | |
.filter('itemFirst', itemFirst); | |
/** @ngInject */ | |
function itemFirst($filter) { | |
var filter = function(input, property, key) { | |
var out = []; | |
if (typeof input !== 'undefined') { | |
if (typeof key !== 'undefined') { | |
var first = $filter('filter')(input,key,true); | |
var everythingElse = $filter('filter')(input,'!'+key,true); | |
out = first.concat(everythingElse); | |
} else { | |
out = input; | |
} | |
} | |
return out; | |
}; | |
return filter; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment