2

I'm calling js function every 2 seconds where on certain condition I want to update div on the view.

 <div id="ball_{{ballIndex}}">{{ball}}</div>

on ng controller

       var myCounter = 0;

        var interval = $interval(function () {
            if (myCounter <= 35) {
                myCounter ++;
                DoSomething();
            } else {
                //
            }
        }, 1500);

        function setCurrentBallEffect() {
            $('#ball_' + myCounter).addClass('magictime puffIn');                
        }

        function DoSomething() {
            if (myCounter == 0) {
                $scope.ballIndex = 1;
            } else {
                $scope.ballIndex = myCounter;
            }
        }

using this code only first div in iteration is applied with class magictime puffIn. When I hardcode div id's on the view side like <div id="ball_1">1</div> <div id="ball_2">2</div> .. applied css class work on each div. What I'm doing wrong?

Update: Tried with

<div ng-attr-id="{{ 'ball_' + ballIndex }}"> </div>

but problem is still present.

3
  • 3
    answered in this post. It's the same issue as why you can't write <a href="{{ngValue}}"> but have to use <a ng-href="{{ngValue}}"> Commented Sep 10, 2015 at 8:18
  • thanks but this did not help, problem is still present. Commented Sep 10, 2015 at 8:34
  • Perhaps I haven't understood your question entirely. When is the function setCurrentBallEffect() ever called? Perhaps provide more code, especially the part where the setCurrentBallEffect() function is called. Commented Sep 10, 2015 at 9:21

1 Answer 1

0

At first you must define

var myCounter =0;

I don't understand ball

you must defined it like this :

$scope.ball=0;

I Change view like this

<div id="ball_{{ballIndex}}">{{ballIndex}}</div>

and your javascript changed like this:

var poolCounter = 0;
    var myCounter = 0;

    var interval = $interval(function () {
        if (myCounter <= 35) {
            myCounter++;
            DoSomething();
        } else {
            //
        }
    }, 1500);

    function setCurrentBallEffect() {
        $('#ball_' + myCounter).addClass('magictime puffIn');
    }

    function DoSomething() {
        if (myCounter == 0) {
            $scope.ballIndex = 1;
        } else {
            $scope.ballIndex = myCounter;
        }
    }
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.