我怎样才能解除(删除)角时没有DOM模型 [英] How can I unbind(remove) angular models when not in DOM

查看:116
本文介绍了我怎样才能解除(删除)角时没有DOM模型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面就是我奋力实现一个简单的演示。

Here is a simple demonstration of what I'm struggling to achieve.

 <div ng-controller="MyCtrl">
     <input type="button" ng-click="a=!a" value="toggle a"/>
     <div ng-if="a">
         <input type="text" ng-model="del.a1" />{{del}}
     </div>
     <input type="text" ng-model="del.a2" />
     {{del}}
 </div>

最初德尔的值是{}和NG-如果是假的属性a1为NG-如果条件下进行。
测试用例:

Initially the value of del is {} and ng-if is false the property a1 is under ng-if condition. Test Case :

第1步:切换NG-如果为true,这样A1是可见的。

step 1 : toggle the ng-if to true so that a1 is visible

第2步:输入一些值变为a1(你可以随时进入房地产A2值)

step 2 : enter some value into a1 (you can anytime enter value in property a2)

第3步:现在,如果我再次拨动NG-如果为false,我要找的是财产A1是从模型中移除(即我只想角度绑定那些对DOM可见机型)等。

step 3 : now if i again toggle ng-if to false what I'm looking for is the property a1 is to be removed from model.(i.e i just want angular to bind those models which are visible on DOM) like this

下面是 FIDDLE 对于上述测试用例。

Here is the FIDDLE for the above test case.

我想这个问题是作为对象模型。但我需要在模型中的解决方案,对象只因为我已经做了很多编码在此基础上的。

I guess the problem is with model used as object. but I need a solution in model as object only as I have done lot of coding based on this.

希望我的问题清楚。

请帮助

推荐答案

在你的榜样,只有在DOM可见模型观看。

In your example only the models visible in the DOM are watched.

如果你的意思是你想从对象中删除该模型值,那么你就需要有'A',知道什么值从模型中取出一块手表。

If you mean you want the model value removed from the object then you would need to have a watch on 'a' that knows what values to remove from the model.

这篇关于我怎样才能解除(删除)角时没有DOM模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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