Me too like using linq in angular apps. Those linq operations are time savers. Fortunately we have a plain javascript library equivalent to this.
linq.js in http://linqjs.codeplex.com/ is awesome and stable.
If someone can port this to bower package in github. That would be much helpful.
However, I tried this below and worked for me,
Full Content in the Plunker - http://plnkr.co/edit/Zy1W3G?p=info
// Add service to your module
//linq.svc.js
(function() {
'use strict';
angular
.module('mymodule')
.factory('$linq', linqService);
function linqService() {
return {
getEnumerable: Enumerable
};
function Enumerable() {
var Enumerable = function(getEnumerator) {
this.GetEnumerator = getEnumerator;
}
...... < Paste the remaining content here >
......
......
// out to global
return Enumerable;
}
}
})();
//Example Usage:
//mycontroller.js
(function() {
'use strict';
angular.module('mymodule')
.controller('mycontroller', MyController);
MyController.$inject = [
'$linq'
];
function MyController(
$linq
) {
var jsonArray = [{
"user": {
"id": 100,
"screen_name": "d_linq"
},
"text": "to objects"
}, {
"user": {
"id": 130,
"screen_name": "c_bill"
},
"text": "g"
}, {
"user": {
"id": 155,
"screen_name": "b_mskk"
},
"text": "kabushiki kaisha"
}, {
"user": {
"id": 301,
"screen_name": "a_xbox"
},
"text": "halo reach"
}]
var queryResult = $linq.getEnumerable().From(jsonArray)
.Where(function(x) {
return x.user.id < 200
})
.OrderBy(function(x) {
return x.user.screen_name
})
.Select(function(x) {
return x.user.screen_name + ':' + x.text
})
.ToArray();
console.log("queryResult==>", queryResult);
}
})();
Example Output:
queryResult==> ["b_mskk:kabushiki kaisha", "c_bill:g", "d_linq:to objects"]