angular ui modal 不能引用父作用域 [英] angular ui modal can NOT refer to parent scope

查看:26
本文介绍了angular ui modal 不能引用父作用域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 angular ui modal 在我的项目中创建模态.

i am using angular ui modal to create modal in my project.

一切正常,直到我需要在父作用域中引用变量.参见 plunker 代码

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.

这篇关于angular ui modal 不能引用父作用域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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