0

I have seen this HTML line in an Angular project:

<div id="player" class="player" [class.voted]="booleanvar">

The CSS contains a defintion of .player.voted

I'm not really sure what this part means: [class.voted]="booleanvar"

CodeMonkey
  • 11,196
  • 30
  • 112
  • 203

2 Answers2

1

This is one way of dynamically applying a class to an HTML element in Angular.

If booleanvar equates to true then the css class voted will be applied, so long as its defined correctly in CSS file. If it equates to false, then the class will not be applied.

<div id="player" class="player" [class.voted]="booleanvar">
devDan
  • 5,969
  • 3
  • 21
  • 40
0

I hope you help it

[class.voted]="booleanvar" this means the element add a class "voted" when "booleanvar" poperty or a variable value is true.

import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  template:`
    <div id="player" class="player" [class.voted]="booleanvar">
  `
})
export class AppComponent {
  booleanvar:boolean = true;
}

when booleanvar = false then the render element like '<div id="player" class="player">'

Otherwise it's render <div id="player" class="player voted">

Md. Abu Sayed
  • 2,396
  • 2
  • 18
  • 26