Javascript Angular指令中的Jquery插件只工作一次
我正在使用这个jquery插件,它允许创建一个“pinterest”网格。我在Angular指令中集成了这个插件,当我第一次加载网页时,它工作得很好。但是,如果我导航到另一个路径并返回到网格,它就不再工作了(它不会按照应该的方式编译) 例如:Javascript Angular指令中的Jquery插件只工作一次,javascript,jquery,html,angularjs,Javascript,Jquery,Html,Angularjs,我正在使用这个jquery插件,它允许创建一个“pinterest”网格。我在Angular指令中集成了这个插件,当我第一次加载网页时,它工作得很好。但是,如果我导航到另一个路径并返回到网格,它就不再工作了(它不会按照应该的方式编译) 例如: 我通过转到网格所在的位置(/food)加载应用程序 然后我导航到此路径(/recipe) 然后我回到这条路(/食物) 指令得到调用,但插件不适用于dom 角度指令: Html 尝试修改“链接”功能,如下所示: function(scope, elem
- 我通过转到网格所在的位置(/food)加载应用程序
- 然后我导航到此路径(/recipe)
- 然后我回到这条路(/食物)
尝试修改“链接”功能,如下所示:
function(scope, element, attrs) {
element.pinterest_grid({
no_columns: 4,
padding_x: 10,
padding_y: 10,
margin_bottom: 50,
single_column_breakpoint: 700
});
scope.$on('$destroy', function(){
// remove all event handlers that were
// bound by the pinterest_grid plugin
// (plugin "destroy" method if there is one)
});
}
您的问题可能是同一事件处理程序的双重/多重绑定,这可能会导致不期望的行为。嘿,您可以在使用angularjs时使用ng grid,ng grid包含许多功能。
<section food-direction><!--some html--></section>
function(scope, element, attrs) {
element.pinterest_grid({
no_columns: 4,
padding_x: 10,
padding_y: 10,
margin_bottom: 50,
single_column_breakpoint: 700
});
scope.$on('$destroy', function(){
// remove all event handlers that were
// bound by the pinterest_grid plugin
// (plugin "destroy" method if there is one)
});
}