Stephan
Stephan

Reputation: 1999

Different way to bind a scope property to a CSS property?

I'm using Visual Studio Code (1.12.2) for a HTML based project that uses Angular. vscode marks the following line as syntactically incorrect, even though from an Angular point of view it is absolutely valid (correct me if I'm wrong):

<div class="meeting-header" style="background: {{ meeting.color }}">

enter image description here

I know that { and } are no valid characters in this context. Still, that makes me wonder whether there is a better way to bind some property in Angular to a CSS property.

So the actual question is

Is there another way in Angular to bind a property in the scope to a CSS property?

Upvotes: 0

Views: 38

Answers (2)

Kristian Jay
Kristian Jay

Reputation: 121

Why not use ng-class and have all those neat styling be separated on your .css file?

ref:

AngularJs 2+

AngularJs <2

Upvotes: 0

Nahuel Veron
Nahuel Veron

Reputation: 532

Yes, use ng-style instead, like this:

<div class="meeting-header" ng-style="{background: meeting.color}">

Read more about it in the documentation

Upvotes: 2

Related Questions