angularjs在一个页面上的多个控制器 [英] angularjs multiple controllers on one page

查看:550
本文介绍了angularjs在一个页面上的多个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个控制器的网页,则控制器中的一个被在2个不同的div使用的同一页内。我不知道这是否是一个范围问题,或者我只是想念我的code的东西。

I have a page with multiple controllers, one of the controller is being used in 2 different divs within the same page. I am not sure if it is a scope issue or I just miss something in my code.

这里是plunkr
<一href=\"http://plnkr.co/edit/IowesXE3ag6xOYfB6KrN?p=$p$pview\">http://plnkr.co/edit/IowesXE3ag6xOYfB6KrN?p=$p$pview

我想,当用户点击储蓄链接隐藏文本框,显示框上的费用链接,点击时。

I want to hide the textbox when the user clicks on 'Savings' link, display the box when clicking on 'Cost' link.

推荐答案

每次使用NG-控制器的时候,你让所述控制器的新实例,与它自己的范围。如果你在身体上的标签(或新的父)设置subCCtrl,并从两个div它是目前在删除它,它为我工作。

Every time you use ng-controller, you make a new instance of said controller, with it's own scope. If you set subCCtrl on the body tag (or a new parent), and remove it from the two divs it is currently on, it works for me.

其他的解决方案,您可能想看看中是通过保持对根范围hideThisBox,在点击保存或通过其保存在一个服务时,广播的事件。

Other solutions you might want to look in to are by keeping "hideThisBox" on the root scope, broadcasting an event when clicking on save or by keeping it in a service.

这篇关于angularjs在一个页面上的多个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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