Working with AngularJS, I have a collection of colors that each have a specific title
and type
. These colors are displayed in a list format on the webpage.
Now, I am looking to enhance this by incorporating a menu option that allows users to filter and view only the colors belonging to a certain type
. To achieve this, I have created another array containing different color types which is also presented as a list.
The goal is to enable users to click on a particular colortype and dynamically filter the displayed colors based on the selected color.type
. This can be accomplished using a filtering mechanism:
<ul>
<li ng-repeat="color in colors | filter:search">
{{ color.title }}
</li>
</ul>
When manually inputting a list of colortypes, everything functions correctly:
<ul>
<li>
<a href="" ng-click="search.type = 'primary';">
Primary
</a>
</li>
</ul>
However, when attempting to utilize an array of colortypes as outlined above, clicking on an item yields no result:
<ul>
<li ng-repeat="colortype in colortypes">
<a href="" ng-click="search.type = '{{ colortype.title }}';">
{{ colortype.title }}
</a>
</li>
</ul>
This issue may stem from the placement of ng-click within ng-repeat (or possibly due to scope constraints related to the =
operator). How can this problem be resolved?