I've been setting up a jquery plugin MixItUp with AngularJS and although I can successfully initiate the container during one of my partial views with NgRoute, once I move to other page views and go back it seems that MixItUp does not know how to initiate setup again.
I’ve tried $(document).ready(), $(window).load, and even $viewContentLoaded but nothing seems to make it work. The whole container simply does not get called when I click on my other pages and return again.
My code as below.
$scope.$on('$viewContentLoaded', function(){
$('#container').mixItUp();
var $container = $('#ContainerP');
if(!$container.mixItUp('isLoaded')){
$container.mixItUp();
}
alert("It's loading!");
});
Everything in the function passes smoothly including the alert message, but somehow mixItUp cannot be called within my routing views…would appreciate greatly if someone could help me out here! Thanks!
I'd recommend you to use directives when you are working with DOM. So you need to create some directive that will initiate MixItUp for you
I spent several hours and finally the solution is here....
Here's the full directive code..
As @demkalkov suggest use a directive and load
mix-it-up
relatedhtml
as template likeUse the
directive
inhtml
asAnd lets say your
mix-it-up.html
looks likeHere is a working Demo
Note - In Angular context directive is the ideal place to manipulate html or plugin integration.
I integrated jQuery MixItUp with AngularJS NgRoute with the use of a custom directive.
I use the AngularJS
$broadcast
and$on
functions to handle communication between Controller and Directive:My view HTML:
In my controller handle jQuery MixItUp with the following calls:
You have to destroy jQuery MixItUp when leaving page. I managed this by adding the following to my controller:
You can also have a look at a very similar question i posted myself: jQuery MixItUp with AngularJS NgRoute