i need to have a list of data that is filtered by its defined property (monitored), i can't just do :
ng-if="project.monitored"
since i need to count unmonitored ones.
for the example i simplified the data returned from getProjects(), which is normally :
this.projects = {
"owned": [
{
"name": "project-1",
"monitored": true
},
{
"name": "project-2",
"monitored": true
}
],
"John Doe": [
{
"name": "project-3",
"monitored": true
},
{
"name": "project-4",
"monitored": false
}
]
};
I'll iterate through this.projects.owner at first then through the rest later in the template. Total of unmonitored here would be equal to 1.
So i guess i can't use such kind of solution
EXAMPLE :
template
<div ng-init="getProjects()">
<div ng-if="vm.isMonitored(project.name)" ng-repeat="project in vm.projects">{{ project.name }}</div>
</div>
controller :
getProjects(){
console.log('init');
this.projects = {
{
"name": "project-1",
"monitored": true
},
{
"name": "project-2",
"monitored": true
}
};
}
isMonitored(name) {
console.log('Name :'+name);
return true;
}
template is correctly displaying 2 results :
project-1 project-2
but the console.log :
init
dashboard.controller.js?e45c:217 Name :project-1
dashboard.controller.js?e45c:217 Name :project-2
dashboard.controller.js?e45c:217 Name :project-1
dashboard.controller.js?e45c:217 Name :project-2
dashboard.controller.js?e45c:217 Name :project-1
dashboard.controller.js?e45c:217 Name :project-2
So i can't understand why i have so many duplicates from console.log while the result displayed on the template is correct.
Therefore if i count anything in ng-if, the result would be wrong. Why? Any solutions?