Angular 4 Template Binding with ES6 Template String

后端 未结 1 972
忘掉有多难
忘掉有多难 2021-01-22 07:18

Something I could do in Vue, but doesn\'t appear to work in Angular 4:

1条回答
  •  滥情空心
    2021-01-22 08:21

    It would be great if this were possible. In the meanwhile, I think a similarly elegant solution would be to have a style object defined in the component class and that is then bound to ngStyle in the template.

    /* my.component.ts */
    export class MyComponent implements OnInit {
      myStyle: Object;
    
      ngOnInit() {
        myStyle = {'transform': `translate3d(${gridTranslateX}px, 0, 0)`};
      }
    }
    
    /* my.component.html */
    
    ...

    0 讨论(0)
提交回复
热议问题