UI的引导模式范围的bug [英] ui-bootstrap modal scope bug

查看:108
本文介绍了UI的引导模式范围的bug的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到有些古怪与UI自举模式的范围。看来,它采用NG-模型时,您必须引用$父去模态控制的范围。在我plunker注意,其它属性这样一个NG选项并不需要$父:
<一href=\"http://plnkr.co/edit/xGSHz4EkZvGr2D6CUeBz?p=$p$pview\">http://plnkr.co/edit/xGSHz4EkZvGr2D6CUeBz?p=$p$pview

I am noticing some weirdness with the ui-bootstrap modal scope. It seems that when using ng-model in it, you have to reference $parent to get to the scope of the modal controller. Notice in my plunker that the other properties such an ng-options doesn't require $parent: http://plnkr.co/edit/xGSHz4EkZvGr2D6CUeBz?p=preview

任何想法,为什么?我发现了一个类似的问题在这里:
与角UI模式

Any idea why? I found a similar issue here: Scope issues with Angular UI modal

这促使我尝试$父变化,但我不能,因为我没有足够的声誉在该线程发表评论。

That led me to try the $parent change but I am unable to comment on that thread because I don't have enough reputation.

任何想法,为什么范围似乎改变?

Any idea why the scope seems to change?

谢谢!

推荐答案

模态有它自己的范围(我从来没有用过角UI,但它是一个可以发生的唯一的事),当你设置selectedLocation 楼市是越来越设置在模式的范围,而不是你的控制器的范围。在$父迫使它来得到你的控制器的范围,但是这并不是一个很好的解决方案,因为你会被锁定你的自我成一定的结构总是假设模态的父母有样板。

The modal has its own scope (I've never used Angular UI, but it's the only thing that can be happening) and when you're setting "selectedLocation" the property is getting set on the modal's scope and not your controller's scope. The $parent is forcing it to got your controller's scope, but that's not a good solution because you'll be locking your self into a certain structure always assuming the parent of the modal has the "model".

下面是一个使用模型对象控制器范围修改Plunker(使用model.selectedLocation)
<一href=\"http://plnkr.co/edit/B5kZaIA5xi2RediUTBK7?p=$p$pview\">http://plnkr.co/edit/B5kZaIA5xi2RediUTBK7?p=$p$pview

Here's a modified Plunker using a model object on your controller scope (using model.selectedLocation) http://plnkr.co/edit/B5kZaIA5xi2RediUTBK7?p=preview

不管怎么说,如果你把你的财产上的类似$ scope.model.selectedLocation改变行为。现在,当我引用model.selectedLocation的模式,模式的范围,没有一个模型对象,因此角上升作用域链到控制器的范围(这确实有一个模型对象)。

Anyways, if you put your property on something like "$scope.model.selectedLocation" that changes the behavior. Now, when I reference "model.selectedLocation" on the modal, the modal's scope doesn't have a model object so Angular goes up the scope chain to your controller's scope (which does have a model object).

观赏约翰·林德奎斯特这个视频,我认为它可以更好地解释它比我能。 :-)
<一href=\"http://egghead.io/lessons/angularjs-the-dot\">http://egghead.io/lessons/angularjs-the-dot

Watch this video from John Lindquist, I think it can explain it much better than I can. :-) http://egghead.io/lessons/angularjs-the-dot

这篇关于UI的引导模式范围的bug的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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