ng-click or jquery alternative

Asked

Viewed 48 times

0

I need, when clicking on the Thumb image, write the image clicked on the div . currentImage

Script

    .directive('galeria',function() {
return {
    templateUrl:'scripts/directives/galeria/galeria.html',
    restrict: 'E',
    scope:{
        'pasta':'@',
        'restrito':'@',
    },
    controller: function($scope,$http){
        // INICIAR CAROUSEL DA HOME 
        $(".thumbsGaleria").owlCarousel({
            autoPlay:true,
            jsonPath: "api/galeria.php?id="+$scope.pasta,
            jsonSuccess: customDataSucesso,
            afterAction: afterFunction
        })
        function customDataSucesso(data){
            var content = "";
            for(var i in data){
                   var img = data[i];
                content += '<img src="painel/modulos/galerias/pastas/'+$scope.pasta+'/'+img+'" ng-click="currentClick('+img+')" style="width:100%; padding-right:10px; max-height:415px">'
             }
            $(".thumbsGaleria").html(content);
        }
        // FIM CAROUSEL

        function afterFunction(elem){
            var current = this.currentItem;
            var src = elem.find(".owl-item").eq(current).find("img").attr('src');
            $(".currentImage").html("<img src='"+src+"' >");
        }

        $scope.currentClick = function(imgCurrent){
            $(".currentImage").html("<img src='"+imgCurrent+"' >");
        }

    }
}  });

HTML

<section class="section box" >
<div class="thumbsGaleria"></div>

<div class="currentImage">
</div>

But the NG-CLICK does not work, when clicking on the item, nothing happens. I tried to put an ONCLICK by clicking the console returns that the specified function does not exist.

  • What’s the matter?

  • Where is the ng-click?

  • There in the customDataSubject(date) function in var content

  • Yes, I hadn’t noticed.. If you 'Inspect' the element after the page has been loaded, ngClick appears in the element?

  • yes, it appears. However, clicking does not execute the function.

  • I think you’re not passing the correct destination within ngClick or you’re not propagating change. Check with Inspect which src is assigned to "currentImg" after clicking. If there is a change in src, check that it is at the correct destination

  • The point is not that you are not running the function by clicking on the ng-click item ...

  • 1

    @When you find a solution, put it as an answer and accept it. Do not put the answer as part of the question. See the [tour].

Show 3 more comments

1 answer

0

PROBLEM SOLVED

replaces $Scope.currentClick with the script below.

        $(".thumbsGaleria").on("click", ".owl-item", function(e){
            var imagem = $(this).find('img').attr('src');
            $(".currentImage").html("<img src='"+imagem+"' >");
        });

Thank you to those who paid attention.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.