Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs isolate scope, what am I missing?

I'm trying to animate some buttons and I don't get it, why the isolate scope is not working. Here's a fiddle:

Fiddle https://jsfiddle.net/gLhveeor/4/

The mouseenter should only trigger the particular animation and not all of the ng-repeat items.

I hope you can help me out.

like image 294
ogermann Avatar asked May 20 '26 14:05

ogermann


1 Answers

It's not scope issue, you are just initializing TimelineLite object with HTMLCollection of elements and then run animation on all of them. Instead select necessary element on mouseover like this:

.controller('myCtrl', function ($timeout, $scope) {
    $timeout(function () {

        var tl = new TimelineLite();
        tl.stop();

        $scope.play = function ($event) {
            var target = $event.target.querySelector('.foo-2');
            tl.to(target, 0.4, {x: 30});
            tl.play();
        };
    }, 0);
});

where in HTML you pass event object into handler:

<div my-directive class="foo" ng-mouseenter="play($event)">

Demo: https://jsfiddle.net/gLhveeor/5/

However advice I can give you is to move this login into directive, having them in controller is not the best idea.

like image 97
dfsq Avatar answered May 22 '26 02:05

dfsq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!