4

I have an Angular 2 app that has a single component currently. For the entire page, I want to render a background image on the page. I have done the following: app.component.html

<dashboard class="dash"></dashboard> 

app.component.css

.dash { background-image: url("../assets/images/background/sligo.jpg"); } 

in the dev tools in chrome, the image is showing up, but on the actual view, it still shows a blank screen. What am I missing? The below snip shows the console output and the main view.

enter image description here

Additional info; here's a snip of my package.json and the folder structureenter image description here

enter image description here

3
  • URL path is fine. You can click the link in the styles box and open the image with the provided url Commented Sep 27, 2017 at 22:40
  • Does the networking tool show all files loading correctly? Commented Sep 27, 2017 at 22:40
  • Yes, I get a compilation error if the URL isn't resolved, but there are no http requests for the file Commented Sep 27, 2017 at 22:44

1 Answer 1

3

You need to specify assets and root properties correctly in your .angular-cli.json, for example:

enter image description here

And the structure of my project:

enter image description here

And you should use content instead of background-image, like this:

.dash { content: url(../assets/images/background/sligo.jpg); } 
Sign up to request clarification or add additional context in comments.

4 Comments

@mcgowan.b, I don't see, assets folder is inside src? There are no parent folders between them?
@mcgowan.b, I have updated the answer with one more try to help, it's at the bottom (about content), try this one.
this overlays the image over the entire page, so I only see the image
@mcgowan.b, you need to add some magic via CSS, I'm using content method in my projects, and it's only the way it works. Try to add another one div and set content property to it (and other needed styles too).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.