How to access global js variable in angular2 component

后端 未结 6 1498
佛祖请我去吃肉
佛祖请我去吃肉 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

    In the component file, outside component class definition, declare rootVar, and it will become available in the component constructor:

    declare var rootVar: any;
    

    then

    @Component(...)
    export class MyComponent {
      private a: any;
    
      constructor() {
        this.a = rootVar;
      }
    }
    

提交回复
热议问题