In my Angular project, I am aiming to utilize a string defined in Typescript within a CSS file. Specifically, I want to set the background image of a navbar component using a path retrieved from a database service. Although I came across suggestions to use [ngStyle]
, it seems like the image won't update dynamically, which is not necessary in my case since I just need the paths from the database. Should I still consider implementing it? If so, how can I do this effectively? I feel a bit confused.
Currently, my Typescript file looks like this:
// ...
export class NavbarComponent{
background_url='../../../assets/img/background.png';
constructor() { }
// ...
On the other hand, in my CSS file, I envisioned doing something along these lines:
nav{
background-image: background_url;
}
However, my attempts have been unsuccessful.
Any suggestions on a better approach for achieving this? Thank you