[英]How to create Global variable in Angular for multiple Components
I wanted to create a global variable which is of type boolean, I wanted to utilize the same variable in multiple components ( Without using Service ).To be precise I also wanted to capture the variable value from any component if it is changed in other components.我想创建一个类型为 boolean 的全局变量,我想在多个组件中使用相同的变量(不使用服务)。确切地说,如果它在其他组件中发生更改,我还想从任何组件中捕获变量值.
try declaring the variable in environment.ts file尝试在 environment.ts 文件中声明变量
There are few options to do it.有几个选项可以做到这一点。
environment.ts
.environment.ts
中声明变量。 Do note that you need to replicate it across envionment.prod.ts
and other environment files if you may have.envionment.prod.ts
和其他环境文件中复制它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.