0

Inside view I have following snippet where I'm iterating trough collection of data

 <div class="tab-content" ng-controller="homeController as vm">
     <div class="tab-pane fade in active" ng-repeat="item in vm.data">
         {{item.Total}} 
         <script>
               var arrValues = [1, 5, 6, 7];
               // how can I access from here to item.Total                                    
         </script>
     </div>
</div>

I tried using following code to access item.Total but I'm getting

Uncaught ReferenceError: item is not defined

if (arrValues.indexOf(item.Total) > -1) {
    console.log('A');
} else {
    console.log('B');
}

p.s. data binding works fine {{item.Total}} render value as expected.

4
  • 1
    This is really not angularish what is your main purpose? Commented Apr 9, 2017 at 18:09
  • you need to use $scope. Looks like plain js Commented Apr 9, 2017 at 18:10
  • @Jagen.. how do you mean it's not angularjs. I'm iterating inside view through collection of data exposed by angularjs controller. Main purpose is to access data inside js function which is displayed fine using data binding {{item.Total}} Commented Apr 9, 2017 at 18:21
  • exposed by angularjs controller - where is it exposed? Please, provide stackoverflow.com/help/mcve Commented Apr 9, 2017 at 18:57

1 Answer 1

1

There are workarounds to achieve what you want, like using angular.element(elementRef).scope().item.

But this is not the recommended way to work with angular, you should manipulate the data in a controller or a service, not in the view.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.