How to access global js variable in angular2 component

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

    In HTML template you can use method get

    {{getGlobalData('rootVar')}}
    

    And create method in component like:

    get getGlobalData() {
        // Closure workaround
        return function(rootVarName) {
            return window[rootVarName];
        }
    }
    

提交回复
热议问题