简体   繁体   English

AngularJS暂时禁止某些视图更新

[英]AngularJS Temporarily disabling certain parts of view from updating

I have a complex view where the user interacts with with many different objects through modals. 我有一个复杂的视图,用户可以通过模式与许多不同的对象进行交互。 Whichever data set corresponds to the active modal is set as $scope.object. 对应于活动模式的任何数据集均设置为$ scope.object。 This works great for what I need. 这非常适合我的需求。 The only downfall is that, in the background, beneath the current modal, the visible data disappears, because the $scope.object has changed. 唯一的缺点是,在后台,当前模式下,可见数据消失,因为$ scope.object已更改。 So for purely aesthetic reasons, I'm trying to figure out a way to temporarily disable AngularJS from updating certain parts of the view. 因此,出于纯粹的美学原因,我试图找到一种方法来暂时禁用AngularJS以更新视图的某些部分。 I could only think of something hacky like this: 我只能想到这样的东西:

$('#my-element [ng-model]').attr('ng-model', 'xx-model');
$('#my-element [ng-repeat]').attr('ng-repeat', 'xx-repeat');

And then reversing the operation when necessary. 然后在必要时反转操作。 But this doesn't work. 但这是行不通的。 Any ideas? 有任何想法吗?

Perhaps you should use different controllers, one for the modal and another one for other purposes, and a service to do what you want. 也许您应该使用不同的控制器,一个用于模态,另一个用于其他目的,并使用一种服务来做您想要的。

Then use your own service with dependency injection inside the respective controller. 然后将您自己的服务与相应控制器内的依赖项注入配合使用。

I appreciate the help. 感谢您的帮助。 Here's what I ended up doing: I duplicate the elements that become empty when my $scope.object changes. 我最终要做的是:复制$ scope.object更改时变为空的元素。 To the user, it looks as if nothing changes: 对于用户而言,似乎没有任何变化:

$('[ng-repeat]').each(function() {
    parent = $(this).parent();
    $(parent).addClass('placeholder');
    placeholder = $(parent)[0].outerHTML;
    $(parent).removeClass('placeholder');
    $(parent).after(placeholder);
});

When my current object ($scope.object) is set back to the original data, I run similar logic that removes the placeholder elements. 当我当前的对象($ scope.object)设置回原始数据时,我运行类似的逻辑来删除占位符元素。 Hope this helps someone. 希望这对某人有帮助。

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

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