S
S
Sergey2016-04-14 11:58:27
JavaScript
Sergey, 2016-04-14 11:58:27

How to access the parent scope through ng-repeat?

There is a pattern

<div class="hockey-DateBlock" ng-repeat="key in ['13 мая', '14 мая', '15 мая', '16 мая', '17 мая', '18 мая', '19 мая', '20 мая']" ng-class="{'active' : $index == ActiveId}">
      {{key}}
    </div>

scope.activeId = function () {
        return currentIndex + 1;
      }

Can't reach activeId due to ng-repat.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey, 2016-04-15
@Sergamers

Solved the problem by passing a two-way link from the directive to the component, and then comparing with the component's variable in ng-repeat

<div class="hockey-Date"
    hockey-date-scroll
    hds-item-width="50"
    hds-active-id="$ctrl.activeId"
    hds-items-length="8">
    <div class="hockey-DateBlock" ng-repeat="date in $ctrl.dates" ng-class="{'active' : $index == $ctrl.activeId}">
      {{date}}
    </div>
  </div>

scope: {
      activeId: '=hdsActiveId'
    },

A
Andrey Belokopytov, 2016-04-14
@belokopytoff

Use controller syntax as
jsbin.com/rokejinite/edit?html ,css,js,output

L
lega, 2016-04-14
@lega

ActiveId is a function, it must be called:
ng-class="{'active' : $index == ActiveId()}"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question