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

动态变量模板表达式中的角度吸引子

  •  1
  • AsGoodAsItGets  · 技术社区  · 7 年前

    @Component({
        selector: 'my-component',
        template: '{{test}}'
    })
    export class MyComponent {
        test = 'myData';
    
        constructor() {}
    
        get myData(): string {
            return 'this is what I want so see in the template';
        }
    }
    

    这是一个非常简单的观点,我试图实现,但基本上,如果我的模板 {{myData}} 我会看到我的getter函数被调用并输出预期的字符串。但是,如果要调用的getter函数名保存在组件中的另一个变量中(想象在我的实际场景中,我有一个数组),有没有办法告诉Angular调用其名称由上面的变量test保存的相应getter?

    1 回复  |  直到 7 年前
        1
  •  1
  •   AsGoodAsItGets    7 年前

    看来 {{this[test]}} 正在工作。

    推荐文章