角度ui模态不能引用父范围 [英] angular ui modal can NOT refer to parent scope
问题描述
我正在使用角度ui模态在我的项目中创建模态.
i am using angular ui modal to create modal in my project.
一切正常,直到我需要在父作用域中引用变量为止.参见插件代码
Everything works fine until I need to refer to variable in parent scope. see plunker code
似乎模态无法访问父作用域.反正有什么要克服的?
It seems like modal can't access parent scope. Is there anyway to overcome this?
推荐答案
默认情况下,Angular UI的模式使用$rootScope
(请参阅此处的文档).
Angular UI's modals use $rootScope
by default (See the documentation here).
打开模态时,可以通过自定义范围传递scope
参数-例如scope: $scope
如果要传递父范围.模态控制器将在该范围内创建一个子作用域,因此您只能将其用作初始值.
You can pass a scope
parameter with a custom scope when you open the modal – e.g. scope: $scope
if you want to pass the parent scope. The modal controller will create a sub-scope from that scope, so you will only be able to use it for your initial values.
这篇关于角度ui模态不能引用父范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!