AngularJS: how to recompile data changes by directive

I am trying to implement lightSlider ( http://sachinchoolur.github.io/lightslider/ ) in a popup that can be opened when the user clicks on the image.

There are many images on the page and anyone can open the popup with a lightSlider. The content of the gallery is different every time.

The problem is that lightGallery is wrapping the div with a lot of extra divs. So every time the "media" changes, I need to find a way to delete the entire element and create a new template and run lightGallery on it.

Little help please ...

Thank!

App.directive('lightGallery', function($compile) {
    return {
        restrict: 'AE',
        scope: {
            media: '='
        },
        compile: function CompilingFunction($templateElement, $templateAttributes) {
            $('.lSSlideOuter').remove();
            $templateElement.replaceWith(this.template);
            return function LinkingFunction($scope, $element, $attrs) {
                $('#imageGallery').lightSlider({
                    gallery:true,
                    item:1,
                    thumbItem:9,
                    slideMargin:0,
                    currentPagerPosition:'center'
                });
            };
        },
        template: '<ul id="imageGallery">'+
                    '<li ng-repeat="item in media.media" data-thumb="{{item.picture}}" data-src="{{item.source}}">'+
                        '<img src="{{item.source}}" />'+
                    '</li>'+
                  '</ul>'
    }
});

      

+3
javascript angularjs angularjs-directive


source to share


No one has answered this question yet

Check out similar questions:

7728
How do I redirect to another web page?
7649
How does JavaScript blocking work?
7494
How can I remove a specific element from an array in JavaScript?
7432
How to check if a string contains a substring in JavaScript?
7428
How can I check if an element is hidden in jQuery?
5722
How can I remove a property from a JavaScript object?
4523
Thinking in AngularJS if I have a jQuery background?
3178
AngularJS: Service vs provider vs factory
1690
How does data binding work in AngularJS?
998
What is the difference between "@" and "=" in scope in AngularJS?



All Articles
Loading...
X
Show
Funny
Dev
Pics