Dan*_*han 6 jquery angularjs ngroute
我一直在使用AngularJS设置一个jquery插件MixItUp,虽然我可以在使用NgRoute的部分视图中成功启动容器,但是一旦我移动到其他页面视图并返回它,似乎MixItUp不知道如何启动设置再次.
我已经尝试了$(document).ready(),$(window).load,甚至$ viewContentLoaded,但似乎没有任何东西可以使它工作.当我点击其他页面并再次返回时,整个容器根本不会被调用.
我的代码如下.
$scope.$on('$viewContentLoaded', function(){
$('#container').mixItUp();
var $container = $('#ContainerP');
if(!$container.mixItUp('isLoaded')){
$container.mixItUp();
}
alert("It's loading!");
});
Run Code Online (Sandbox Code Playgroud)
函数中的所有内容都顺利通过,包括警报消息,但不知何故mixItUp无法在我的路由视图中调用...如果有人可以帮助我,我会非常感激!谢谢!
小智 0
我建议您在使用 DOM 时使用指令。所以你需要创建一些指令来为你启动 MixItUp
angular.module('app').directive('myNgMixitup', [function(){
return {
restrict: 'AEC',
link: function(scope, element){
//now you can access the element/container
element.mixItUp();
}
};
}])
Run Code Online (Sandbox Code Playgroud)