How to access global js variable in angular2 component

后端 未结 6 1500
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-03 10:54

I have a global js variable defined below (@Url is an ASP.Net MVC html helper it will get converted to a string value):



        
6条回答
  •  臣服心动
    2020-12-03 11:18

    Here don't forget to wash your hands... Angular is just javascript

    //Get something from global
    let someStuffFromWindow= (window).somethingOnWindow;
    
    //Set something
    (window).somethingOnWindow="Stuff From Angular";
    

    This is bad for some reason.. you should feel bad!

    Go ahead and use that find and replace fuction for window. with (window).

提交回复
热议问题