“毁灭"ng-如果表达式为真 [英] "destroy" ng-if once expression is true

查看:75
本文介绍了“毁灭"ng-如果表达式为真的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道一旦其值为true,是否可以解除绑定/销毁 ng-if ?

I am wondering if is possible to unbind/destroy ng-if once its value is true?

我用递归指令创建了树结构,并且每个分支都有< div ng-if ="visible"> ,它可以跟踪是否需要渲染元素.问题在于该解决方案增加了观察者的数量,因为每个 ng-if 都会创建一个新的观察者.一旦 ng-if 表达式变为 true ,它就不会更改,因此可以删除表,是否有任何方法可以销毁" ng-if 在这种情况下?

I created tree structure with recurrence directive and each of branches has <div ng-if="visible"> which keeps tracking if element needs to be rendered. The problem is that the solution increase number of watchers because every ng-if creates new one. Once the ng-if expression became true it won't change so watch can be removed, is there any way to "destroy" ng-if in that case?

推荐答案

如果使用angular 1.3+,则可以

if using angular 1.3+ you can do

<div ng-if="::visible">

这将从角度监视列表中删除该表达式,并且在该监视列表上基本上没有监视.将此用于您应用程序中的任何单个绑定表达式.保持手表数量少,消化周期更快.

Which will remove the expression from angular watchlist and essentially no watches on it. Use this for any single binded expressions in your app. Keeps your watch count low and digest cycles faster.

这篇关于“毁灭"ng-如果表达式为真的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆