我们如何使用控制器在angularjs中不同HTML文件中的两个不同控制器之间共享数据 [英] How can we use controllers to share data between two different controllers in different HTML files in angularjs

查看:99
本文介绍了我们如何使用控制器在angularjs中不同HTML文件中的两个不同控制器之间共享数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用angularjs开发Web应用程序. 我想将chat.html中的chatCtrl(controller)中填充的数据添加到chatScrn.html中的另一个控制器(chatScrnCtrl)中,即通过ng-view这两个html都不同.我希望您能听到我所说的,我正在设计一个Web Messenger应用程序,一旦我输入聊天列表,我就需要将聊天添加到聊天屏幕中.我还需要在聊天记录页面中显示这些内容.希望你们能理解我的需求.因此,请提供一种解决方法,而不是向我提供在相同html文件或相同js文件中访问控制器的解决方案.

I have been using angularjs for developing web applications. I want to add the data filled in chatCtrl(controller) in chat.html to another controller (chatScrnCtrl) in chatScrn.html, i.r both the html are different through ng-view. I hope you get what im saying, im designing a web messenger application and i need to add the chat to the chatscreen once i type in the chatlist. I also need to display these in the chat history page. Hope u guys understand what i need. so pls provide a way for this rather than providing me the solution to access controllers in the same html file or the same js file.

推荐答案

尝试利用angularjs提供的服务,请使用 $ broadcast在控制器之间传输数据

这篇关于我们如何使用控制器在angularjs中不同HTML文件中的两个不同控制器之间共享数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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