I am facing an issue where I have a factory with 2 controllers. The first controller returns an entire array, while the second controller is supposed to return only one item based on a specific filtering expression. I need to extract the last two parameters from the URL, loop through the array, identify the array item that matches the value of a specific attribute, and then return that element with all its attributes and values. This part is not a problem, but I'm unsure how to achieve this in Angular if I want to filter within the array itself inside the factory.
If you need further clarification, I have included a link to a JSFiddle that provides a brief explanation in the HTML section: https://jsfiddle.net/65224mk6/
Below are my current factory and controllers in case you prefer not to visit the link:
portApp.factory("workFactory", function() {
var selected = [];
var works = [
{
Title: "Sprite",
subTitle: "",
Link: "sprite",
Thumbnail: "img/portfolio02.png",
Image: "img/ismont.png"
},
{
Title: "Pepsi",
subTitle: "Kristályvíz",
Link: "pepsi",
Thumbnail: "img/portfolio03.png",
Image: "img/sanofimont.png"
}
];
return {
list: function() {
return works;
},
selected: function() {
return works[0]; // maybe selected[]?
}
};
});
portApp.controller("listController", ["$scope", "workFactory",
function($scope, workFactory) {
$scope.allWorks = workFactory.list();
}
]);
portApp.controller("itemController", ["$scope", "workFactory", "$stateParams",
function($scope, workFactory, $stateParams) {
var detPath = $stateParams.itemLink;
//$scope.selectedWork = workFactory.selected(detPath);
}
]);