Angular 4 Template Binding with ES6 Template String

后端 未结 1 952
忘掉有多难
忘掉有多难 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 */
    <div class="time-translate" [ngStyle]="myStyle">...</div>
    
    0 讨论(0)
提交回复
热议问题