Angular-UI Modal 中奇怪的单向绑定 [英] Strange one-way binding in Angular-UI Modal

查看:24
本文介绍了Angular-UI Modal 中奇怪的单向绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Angular-UI-Bootstrap Modal 中遇到了一种奇怪的单向绑定行为.

I am running into a strange one way binding behavior within a Angular-UI-Bootstrap Modal.

在模态 html 中,两天数据绑定似乎工作正常,但控制器中的范围变量模型由于某种原因没有更新.

Inside a modal html, two day data binding seems to work fine but the scope variable model at the controller does not update for some reason.

然而,如果范围变量是一个对象,那么双向绑定似乎会传播到控制器.

If, however, the scope variable is an object, then the two way binding seems to propagate to the controller.

有谁知道为什么会这样?无论如何要修复它?

Does anyone know why this is happening? Anyway to fix it?

我做了一个 plunker 来演示这个问题.

I have made a plunker to demonstrate the problem.

模态问题中的单向绑定

推荐答案

这似乎是我看到人们在使用 angular 时遇到的最常见问题;嵌套范围.查看以下资源:http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html

This seems to be the most common problem I see people having with angular; nested scopes. Have a look at the following resource: http://jimhoskins.com/2012/12/14/nested-scopes-in-angularjs.html

这基本上归结为以下几点.如果您尝试访问 $scope.someVal,angular 将向上搜索父链以查找 someVal,如果找到将返回给您.如果您尝试更改 someVal,它只会为当前范围创建一个新的 someVal.

This essentially boils down to the following. If you attempt to access $scope.someVal, angular will search up the parent chain looking for someVal, and if found will return it to you. If you try and change someVal, it will simply create a new someVal to the current scope.

然而,如果您尝试访问 $scope.someObj.someVal,则读取的方式相同.除了这一次,如果您尝试更改 someVal,它将更改 someObj 中的值,无论哪个范围正在命令更新.

If however you attempt to access $scope.someObj.someVal, reading acts the same way. Except this time if you try to change someVal, it will change the value inside someObj, no matter which scope is commanding the update.

这篇关于Angular-UI Modal 中奇怪的单向绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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