Global variables in AngularJS

前端 未结 12 1936
被撕碎了的回忆
被撕碎了的回忆 2020-11-22 12:05

I have a problem where i\'m initialising a variable on the scope in a controller. Then it gets changed in another controller when a user logs in. This variable is used to co

12条回答
  •  臣服心动
    2020-11-22 12:08

    It's actually pretty easy. (If you're using Angular 2+ anyway.)

    Simply add

    declare var myGlobalVarName;
    

    Somewhere in the top of your component file (such as after the "import" statements), and you'll be able to access "myGlobalVarName" anywhere inside your component.

提交回复
热议问题