mercredi 22 juillet 2015

Problems using ng-repeat and 'unique'

My issue is a puzzling one. When I make use of ng-repeat to repeat through my data to create checkboxes it works as I expect. I will get all the things I referred to and they have duplicates. An snippet is below.

 <label ng-if="project.score !='0'" data-ng-repeat="project in projects | unique:'c.projectRef' | orderBy:'c.projectRef'">
                    <input
                        id="project.c.projectRef"
                        type="checkbox"
                        ng-click="toggleSelection(project.c.projectRef)"
                        ng-checked="selectedRefs.indexOf(project.c.projectRef) > -1" />
                        <span>{{project.c.projectRef}}</span>
</label>

As you can see,'unique' is in there and I'm making use of Angular UI for that. There's numerous duplicate references and as I am using the checkboxes as a filter, I only want distinct checkboxes as opposed to as many checkboxes as the times it is referenced which is what ng-repeat alone will do.

It functions exactly like that if I remove unique but when I have unique in what happens is instead of giving me several checkboxes that are all unique, it just gives me one checkbox.

From what I've been testing, it appears this happens when you refer to (sorry I don't know the term for it) data when you have deeper references into it so project.c.projectRef as opposed to project.projectRef.

I'm stumped by this issue so any fixes as well as information on the issue would be greatly appreciated.




Aucun commentaire:

Enregistrer un commentaire