Angular 6 属性中字符串插值的最佳实践是什么?
我有这个代码:
<div class="container" [ngStyle]="{'grid-template-rows': 'repeat(' + value + ', 1fr) [last-line]'}">
我想使用类似'repeat(${value})'
的东西带反引号
最佳答案
您可以尝试将功能移至组件并在那里使用反引号:
calculateStyle(value: string): string {
return `repeat(${value}, 1fr) [last-line]`;
}
在模板中:
<div class="container" [ngStyle]="{'grid-template-rows': calculateStyle(value)}">
关于javascript - 属性模板中的 Angular 字符串插值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52442592/