Angular – What is the meaning of brackets [] in the HTML template?

Angular

Angular is a platform and framework for building single-page client applications using HTML and TypeScript.

The brackets, [], cause Angular to evaluate the right-hand side of the assignment as a dynamic expression.
Without the brackets, Angular treats the right-hand side as a string literal and sets the property to that static value.

Example

The right-hand side of the assignment [ngClass]="classes" is a property, not a string.

component.ts

classes = "class-1 class-2 class-3";

component.html

<p [ngClass]="classes">Brackets demo</p>

// output
// <p class="class-1 class-2 class-3">Brackets demo</p>
https://www.mldgroup.com

Vyštudovaný top manažér pôsobiaci najmä ako manažér, marketér, softvérový inžinier, konzultant, bloger, YouTuber a zatiaľ neúspešný hudobník a producent. V rámci praxe pôsobil v rôznych odvetviach na rôznych pozíciách v malých aj veľkých firmách, vrátane spoluprác a partnerstiev s významnými firmami či poradenskými spoločnosťami.

Pridaj komentár

Vaša e-mailová adresa nebude zverejnená. Vyžadované polia sú označené *