Sunil
Sunil

Reputation: 21396

Convert style attribute to ng-style

I have following style in an angularjs application, which is working fine. Can this be replaced by ng-style, or its better to stick to the style attribute as I have it now?

style="border-bottom:solid {{command.name == 'Delete' ? '1px':'0px'}} lightgray;
                      padding-bottom:{{command.name == 'Delete' ? '10px':'0px'}};

The ng-style code that I tried but which didn't work.

ng-style="{border-bottom:solid {{command.name == 'Delete' ? '1px':'0px'}} lightgray;
                   padding-bottom:{{command.name == 'Delete' ? '10px':'0px'}}; }"

Upvotes: 1

Views: 1309

Answers (1)

Mathew Berg
Mathew Berg

Reputation: 28750

That's because it takes an object, no need to do {{}} in there:

ng-style="{
    borderBottom: 'solid ' + (command.name == 'Delete' ? '1px':'0px') + ' lightgray',
    paddingBottom: (command.name == 'Delete' ? '10px':'0px')
}"

Upvotes: 5

Related Questions