What’s the difference between [style] and [ngStyle] in Angular?

<p>The above code would style the&nbsp;<code>div</code>&nbsp;using a color value set on the&nbsp;<code>errorMessageColor</code>&nbsp;property of your component. Thanks to the data binding, whenever that property changes, the&nbsp;<code>div</code>&nbsp;would get a new color.</p> <p>You can make the above example even more powerful using the ternary operator in your expression to express a conditional styling:</p> <pre> &lt;div [style.color]=&quot;hasError ? &#39;red&#39; : &#39;black&#39; &quot;&gt; The phone number you entered does not match the expected format &lt;/div&gt;</pre> <p>The above example assumes that&nbsp;<code>hasError</code>&nbsp;can evaluate to&nbsp;<code>true</code>, which is convenient since in Javascript anything that is not&nbsp;<code>null</code>&nbsp;or&nbsp;<code>undefined</code>&nbsp;would work. As a result, if&nbsp;<code>hasError</code>&nbsp;is something that isn&rsquo;t&nbsp;<code>null</code>&nbsp;or&nbsp;<code>undefined</code>&nbsp;or&nbsp;<code>false</code>, then the message will show up in red color, otherwise it will be black.</p> <p><a href="https://blog.angulartraining.com/whats-the-difference-between-style-and-ngstyle-in-angular-68a3301c2ae6"><strong>Visit Now</strong></a></p>
Tags: Angular