简体   繁体   English

声明全局变量

[英]Declare global variable

I am doing an application in Angular 2 and I need to declare global variable which will be accessible all the users in application. 我在Angular 2中做一个应用程序,我需要声明全局变量,该变量将可供应用程序中的所有用户访问。 THhe application should work only on front and backend with Angular. 该应用程序只能在Angular的前端和后端运行。

let users: User[] = / ...user list /;

If one user in a browser update this list I am looking for away to reflect this change for all the sessions to this application. 如果浏览器中的一个用户更新了此列表,那么我正在寻找可以反映此应用程序所有会话的此更改。 So if one new user added the list of user will be update for all sessions in different browsers. 因此,如果添加了一个新用户,则该用户列表将针对不同浏览器中的所有会话进行更新。

I am not 100% sure but, it is impossible without using any backend. 我不确定100%,但是不使用任何后端都是​​不可能的。 For example when you are using Firebase/Firestore live database you can create special collection and document in that database and you can subscribe to this document. 例如,当您使用Firebase / Firestore实时数据库时,可以在该数据库中创建特殊集合和文档,也可以订阅此文档。 Every time you change sth every instances will see it. 每次更改时,每个实例都会看到它。

Here you have link to firestore tutorial: https://angularfirebase.com/lessons/firestore-with-angularfire-basics/ 在这里,您可以链接到Firestore教程: https : //angularfirebase.com/lessons/firestore-with-angularfire-basics/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM