Categories
Angular Answers

How to set Angular background image with TypeScript?

Spread the love

Sometimes, we want to set Angular background image with TypeScript.

In this article, we’ll look at how to set Angular background image with TypeScript.

How to set Angular background image with TypeScript?

To set Angular background image with TypeScript, we set the [style.background-image] attribute.

For instance, we write

<div [style.background-image]="'url(/images/' + imgUrl + ')'"></div>

to set the [style.background-image] attribute to the string with the URL of the background image.

Conclusion

To set Angular background image with TypeScript, we set the [style.background-image] attribute.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *