0

everyone. I am not experienced with angular, so help needed. i have a directive :

app.directive('ngDirective', [ '$timeout', function ($timeout) {
  return {
    templateUrl: '../tpl/tpl.html',
    restrict: 'E',
    scope:{
        item:'=',
    },
    link:function(scope, element, attrs) {
        //some func here


        scope.myFunction =function(item){
                 $(element).find('.myitem').css('-webkit-transform','scale(0.6)').animate({opacity:0},function(){
                $timeout(function(){
                    var ListIndex = scope.$parent.$index;
                    scope.$parent.$parent.ItemsList.splice(ListIndex, 1);
                    scope.$parent.$parent.updateSomeStuff();
                });
            })

        };
    }
};
}]);

the problem is that scope.myFunction fires jQuery changes twice, first at the element, and then at its sibling at the list;at the same time it only deletes one element from list. if i remove parent scope functionality-jQuery works fine and fires one single time.if i remove jquery line -parent scope func works perfect, how i need to organize this correctly? i think that deleting from a list somehow binds jquery to run again, but i have no understanding of the process... What i am missing?

  • have u used directive at two places in your view ?. – Shushanth Pallegar May 21 '16 at 19:33
  • 2
    Not a solution but never use `ng` prefix for your custom code, it implies it is part of angular core. Suggest you create a [plunker demo](http://plnkr.co/edit/?p=catalogue) that reproduces problem – charlietfl May 21 '16 at 19:39
  • Shushanth Pallegar, no only once. my experiments with part of code shows that problem only occurs when jQuery an scope fucn needed together. i think it is about steps of the process-how this directive will bind the view and what oreder of events will be taken. may be i am wrong – vobatukina May 21 '16 at 19:51

0 Answers0