How to bind static variable of component in HTML in angular 2?

The scope of binding expressions in a components template is the components class instance.

You can’t refer to globals or statics directly.

As a workaround you can add a getter to your components class

export class UrlComponent {

  static urlArray;
  constructor() {
    UrlComponent.urlArray = "Inside Contructor";
  }

  get staticUrlArray() {
    return UrlComponent.urlArray;
  }

}

and use it like:

<div>
  url works! {{staticUrlArray}}
</div>

Leave a Comment

techhipbettruvabetnorabahisbahis forumueduedueduseduseduseduseduseduseduedu