I wanted to make bar that scroll with webpage's main header bar and shows history of skills user searched for.
When user hovers over listed skill (ng-mouseover), it should be highlighted and cross image should be changed.
When user's cursor leaves the skill (ng-mouseleave), the highlight should disappear and image should be changed.
It works when I hardcode the skills list into html.
But when I try to use mocked values (from variable which is in controller), which are rendered by ng-repeat, the skills aren't get even rendered.
Snippet of .html:
<div class="listed-skills">
<ul>
<li ng-repeat="skill in skillsList" ng-init="this['crossIcon' + skill.num] = false" ng-mouseover="this['crossIcon' + skill.num] = true" ng-mouseleave="this['crossIcon' + skill.num] = false">
<span class="history-skill-name">{{skill.name}}</span>
<img src="/images/header-skillbar-cross-dark.svg" alt="Delete skill from search history" ng-if="this['crossIcon' + skill.num] == true" />
<img src="/images/header-skillbar-cross-light.svg" alt="Delete skill from search history" ng-if="this['crossIcon' + skill.num] == false" />
<span class="skill-list-separator">|</span>
</li>
</ul>
</div>
And scope variable inside .coffee:
$scope.skillsList = [
{name: "Piano", num: 1},
{name: "Hiking", num: 2},
{name: "Cycling", num: 3},
{name: "Football", num: 4},
{name: "Computer programming", num: 5},
{name: "Kung-Fu", num: 6}
]
According to this answer (Dynamic ng-init variable - Angularjs),
ng-init="this['Foo' + foo.Bar] = blah"
is one of correct ways to create dynamic ng-init variables.
But when my app's getting run, those skills aren't rendered by angular. I see in chrome dev tools only this:
<!-- ngRepeat: skill in skillsList -->
No error in console, though. What's happening and how I can repair that?