I couldn't think of a great way to title this question, but essentially I'm wondering what the best solution is for evaluating expressions within Ng-Repeat. For example, if I have some code that looks like this that lists out my projects (assuming I have a form with ng-click associated with a function to add the contents to an array of projects, with an associated array of milestones for each project).
<h2>List of Projects!</h2>
<ul>
<li ng-repeat="project in projects">
<p>{{project.name}}</p>
<li ng-repeat="milestone in project.milestones">
<p>{{milestone.name}}</p>
<p>{{milestone.dateAccomplished}}</p>
</li>
</li>
<ul>
Now here is where my problem lies. Since each milestone has a dateAccomplished associated with it, I want to create another list that chronologically prints off ALL of the milestones for all of the projects, with their associated project and date. My thought was to loop through all of the projects, get all their milestones, and use an angular filter by dateAccomplished (which I think would work), but where can I leverage ng-repeat in this scenario?
Essentially, I know how to solve this problem on paper, but I do not know how to solve it the Angular way. I can't figure out a way to loop through my projects (using ng-repeat) without creating extra HTML that I don't want to deal with. Am i over-thinking it? Should i call a function within the ng-repeat parameters that does some work for me, such as
<li ng-repeat="milestone in getAllMilestones()">
Thanks for your help.
Edit: JSON object for project looks like this:
project = {
name: "some string",
milestones: [{
title: "some string",
date: Date.now()
]}
}
Edit 2: JS-Fiddle: http://jsfiddle.net/HB7LU/1672/
NOTE: The fiddle is working how I want it to, thanks to imcg's comment; however, Nahn's answer seems to indicate that I should use a service and inject that service, so perhaps I'm still not quite there yet.