简体   繁体   English

角度,嵌套重复破坏指令(packery + dragabilly)

[英]angular, nested repeat breaking directive (packery + dragabilly)

I am having a slight issue with using dragabilly in angular, the problem is odd because it was working until I made some changes to how the content using packery is loaded in, specifically adding a level of nested repeats. 我在使用有角度的dragabilly时遇到了一个小问题,问题很奇怪,因为它一直有效,直到我对如何加载使用packery的内容进行了一些更改,特别是添加了嵌套重复的级别。 When I do this, packery still runs correctly, however it seems dragabilly only runs on the first object. 当我这样做时,packery仍然正确运行,但它似乎只能在第一个对象上运行。

The html looks like - HTML看起来像 -

 <div class="item gs-w" ng-class="widget.size" ng-repeat="widget in contentHere" packery-angular >
    <!-- nested repeat -->
    <div ng-repeat="side in widget.sides" ng-show="side.active">

So it's just a nested repeat where packery runs off of the outer items, and again, the packery element works fine. 所以它只是一个嵌套的重复,其中packery运行外部项目,并且再次,packery元素工作正常。 It broke when I Added in the nested repeat - these objects have multiple faces which I hide with that side.acive you see there, however the drag handle is inside the nested repeat and I think this may be the problem, or perhaps the nested is taking a bit longer to load in and it doesn't recognize the handle in time? 当我在嵌套重复中添加它时,它会破坏 - 这些对象有多个面,我隐藏在那边。你看到那里的内容,但是拖动句柄在嵌套重复内部,我认为这可能是问题,或者嵌套是加载时间稍长,并且无法及时识别手柄? I'm not too sure and that's where I could use some direction. 我不太确定,那是我可以使用某个方向的地方。

Here is the directive - http://jsfiddle.net/yq4zwLzs/ . 这是指令 - http://jsfiddle.net/yq4zwLzs/ The only thing I added to it was that mobile UA check to try and turn off dragabilly on mobile devices because it's unnecessary at that point. 我添加的唯一内容是移动UA检查尝试在移动设备上关闭可拖动性,因为在那时它是不必要的。 I Tried taking that off it doesn't seem to effect anything. 我试过把它取下来它似乎没有任何影响。

Here is a plunker of it in action - 这是它的一个实际的吸收者 -

http://plnkr.co/edit/HSVztH3vlf5VI1lf1tFR?p=preview http://plnkr.co/edit/HSVztH3vlf5VI1lf1tFR?p=preview

Forgive the ugliness - but if you look, you can move around the top item, but not the bottom item. 原谅丑陋 - 但如果你看,你可以移动顶部项目,但不是底部项目。 That is where I am stuck and I cannot seem to figure out how or why this is happening. 这就是我被困住的地方,我似乎无法弄清楚这是怎么发生的。 You can drag the items by the .handle (title element). 您可以通过.handle(标题元素)拖动项目。 I would appreciate any help as I seem to be stuck here. 我会感激任何帮助,因为我似乎被困在这里。

Thanks for reading! 谢谢阅读!

Update 更新

It seems even if I put the .handle outside of the inner repeat, it still has the same problem. 即使我把.handle放在内部重复之外,它仍然有同样的问题。 Perhaps it has to do with the order the inner repeat and the angulary packery run? 也许它与内部重复和角度包装运行的顺序有关?

Update 2 更新2

It appears the drag handle logic is not working at all, you can drag by anything, not just .handle 看起来拖动句柄逻辑根本不起作用,你可以拖动任何东西,而不仅仅是.handle

Update 3 更新3

I am almost certain this has to do with the nested ng-repeat (perhaps it interacting in conjunction with how the directive runs on the object), because no matter what I try, as long as I have the nested repeat, I have the same issue. 我几乎可以肯定这与嵌套的ng-repeat有关(也许它与指令在对象上运行的方式相互作用),因为无论我尝试什么,只要我有嵌套重复,我都有相同的问题。 If I pull it off it goes back to working as normal, however It will be hard to achieve my desired goal without it :(. 如果我把它拉下来就会恢复正常工作,但如果没有它我很难实现我想要的目标:(。

Also - if i turn 另外 - 如果我转

var draggable2 = new Draggabilly(element[0], {handle: '.handle'} );

into

var draggable2 = new Draggabilly(element[0] );

It works fine. 它工作正常。 I need a drag handle though, as there will be content inside these divs the user will interact with, and I don't want the div moving around when they are clicking around inside it. 我需要一个拖动手柄,因为这些div中的内容将与用户进行交互,我不希望div在它们内部点击时四处移动。 Maybe if there is a way to initiate dragabilly a little bit later? 也许如果有一种方法可以稍后启动dragabilly?

Looks like it might be a digest issue, as if you stick the Draggabilly creation in a $timeout it works as expected 看起来它可能是一个摘要问题,就好像你将Draggabilly创建坚持在$ timeout中它按预期工作

if(!isMobile()){
    $timeout(function(){
        var draggable2 = new Draggabilly(element[0], {handle: '.handle'} );
        $rootScope.packery.bindDraggabillyEvents(draggable2);
    })
}

http://plnkr.co/edit/qxv1VWPHZEKX3pVHgBi2?p=preview http://plnkr.co/edit/qxv1VWPHZEKX3pVHgBi2?p=preview

One thing of note i noticed whilst fiddling around with it, is if you use a different option than handle , for example { axis: 'x'} then it works without the need for the $timeout . 有一点需要注意的是,当你摆弄它时,如果你使用的是另一个选项而不是handle ,例如{ axis: 'x'}那么它可以在不需要$timeout

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM