How to access a constant in an Angular 2 component and service?

后端 未结 5 918
你的背包
你的背包 2020-11-28 12:45

I have a constants file constants.ts:

export const C0NST = \"constant\";

I access it in a service some.service.ts<

5条回答
  •  北海茫月
    2020-11-28 13:02

    The scope of Angular2 template bindings is the component instance. Only what's accessible there can be used in bindings.

    You can make it available like

    class MyComponent {
      myConst = CONST;
    }
    
    {{myConst}}
    

提交回复
热议问题