Search code examples
angularjsng-style

Default value for AngularJS ng-style


I must be missing something with the syntax, but how can I have a default background color if the scope variable is unpopulated?

The following doesn't work for me:

ng-style="{('backgroundColor':button.color || '#FF6600')}"

However, this syntax works elsewhere:

<p>{{button.label || 'Some Text'}}<p>

What am I doing wrong with the ng-style syntax?


Solution

  • Just remove the additional parenthesis and it will work:

    ng-style="{'backgroundColor':button.color || '#FF6600'}"