【发布时间】:2022-01-25 23:26:22
【问题描述】:
我想将属性设置为字符串,并将其作为类列表值动态添加到某个 DOM 元素中。
<div [className]="propertyVariable"></div>
在类组件内部:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-order',
templateUrl: './order.component.html',
styleUrls: ['./order.component.css'],
})
export class OrderComponent implements OnInit {
propertyVariable: string;
constructor() {}
changePropertyVariable() {
this.propertyVariable = 'class1 class2';
}
ngOnInit(): void {}
}
到目前为止,它没有将设置的类列表添加到该变量。如何正确绑定到该属性?
【问题讨论】:
标签: javascript html node.js angular ecmascript-6