代码之家  ›  专栏  ›  技术社区  ›  Vik

在html文件中引用常量的角度材质

  •  0
  • Vik  · 技术社区  · 7 年前

    我定义了如下常量

    常量。ts

      export const Constant = Object.freeze({
           ACCEPTED_LEADS_TO_CALL: "Accepted Leads to Call",
           RECOMMENDED_CALL_LIST: "Recommended Call List"
         });
    

    这非常便于参考。ts文件,如

    import { Constant } from '../constants'
    
    var str = Constant.RECOMMENDED_CALL_LIST
    

    但我如何在中引用它。组件的html?

    我的组件。html

    <div>name: {{Constant.RECOMMENDED_CALL_LIST}}</div> 
    

    失败,出现编译时错误,因为它无法解析常量。

    1 回复  |  直到 7 年前
        1
  •  2
  •   user4676340 user4676340    7 年前

    在组件中添加对常量的引用

    export class MyComponent {
      constants = Constant;
      ...
    }
    

    然后,您可以在模板中使用它:

    <p>{{ constants.RECOMMENDED_CALL_LIST }}</p>