假设我有一个 Angular 4 组件,代码如下:
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
})
export class HomeComponent implements OnInit {
printThisValue = 'customAttr';
constructor(){}
}
如何像下面代码所示一样打印HTML标签内的值:
<div class="myStyle" {{ printThisValue }} ></div>
上面的HTML代码似乎无法正常工作。我知道您可以像这样打印值:
<div class="myStyle">{{ printThisValue }}</div>
// or like this
<div class="myStyle {{ printThisValue }}"></div>
但是我该怎么做呢?
<div class="myStyle" [attr.customAttr]="printThisValue"></div>
。 - dotconnor