question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Plugin doesn't work within Angular ng-repeat directive

See original GitHub issue
 //Magnific-popup

$(‘.single-popup’).magnificPopup({ type: ‘image’, removalDelay: 300, mainClass: ‘mfp-with-fade’, closeOnContentClick: true });

An example from the site copied/pasted works fine, however anything with a databinded href value that is pathed via ‘…/’ does not work. Instead it routes my site to the home page. There are no additional functions on the images not working.

The code

magnificpopup href issue

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:11

github_iconTop GitHub Comments

1reaction
tranelchcommented, Oct 14, 2016

Dear friend!

I need some help, please ask a couple of simple questions regarding my new article, here they are http://personal.thetootclassic.com/e4vxck

chris

1reaction
aaackermancommented, Jan 22, 2015

Hi @Bradmartin0905, thank you for posting this issue, as it clarified a few problems I was having with my own AngularJS app. I’m suffering from the same problem with ng-repeat and found a workaround that I thought I would share with you until this is resolved. Many jQuery plugins don’t work with dynamically generated DOM elements (like ng-repeat). I suggest using some sort of $watch along with a $timeout to check when the ng-repeat is loaded, then you initialize magnific-popup.

$scope.$watch("images", function (newValue, oldValue) {
  $timeout(function() {
    $('.gallery').each(function() {
      $(this).magnificPopup({
        delegate: '.image',
        type:'image',
        gallery: {
         enabled: true
        }
     });
    });
  });
});

This isn’t the most elegant solution, but I’m sure it can be improved with time. Good luck figuring it out and hope this helps! I should note, just make sure to have your gallery (or whatever you choose to call it) class outside of the ng-repeat div.

<div class="gallery">
  <div ng-repeat="image in images">
    <a href="{{image.src}}" class="image"><img src="{{image.src}}"></a>
  </div>
</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Jquery plugin not working inside AngularJS ng-repeat
I'm trying to use a Jquery plugin (Star Rating plugin - link) inside AngularJS's ng-repeat directive but I dont know why its not...
Read more >
Top 18 Most Common AngularJS Developer Mistakes - Toptal
In this article you will learn about most common AngularJS developer ... Many directives create child scopes such as ngRepeat , ngIf ,...
Read more >
ngRepeat - AngularJS: API
The ngRepeat directive instantiates a template once per item from a collection. Each template instance gets its own scope, where the given loop...
Read more >
AngularJS: ng-repeat list is not updated when a model ...
<div ng-repeat="pluginD in pluginsDisplayed"> <div k2plugin pluginname="{{pluginD.name}}" ... Could you explain me why this doesn't work?
Read more >
directive : ng-repeat before call jquery plugin (using transclude ?)
I tried by compiling myself and using $apply() before I call the plugin. It works but angularjs thow an exception on $apply() saying...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found