0

I have a problem with displaying background img in angular. I am using function with ngStyle in html tag and it works fine, but when i upload whole project on github pages imgs with this method doesn't show up. Other images that i add with img tag works fine. Could help me fix it ?

Code:

getHeaderBackgroundImg() {
    return `url(/assets/images/4.jpg)`
  }
<header [ngStyle]="{'background-image': getHeaderBackgroundImg(), 'background-position' : 'center', 'height' : '950px', 'width' : '100%'}" class="main__container"></header>

2 Answers 2

1

remove / from the beginning of your path (relativity)

getDescriptionBackgroundImg() {
    return `url(assets/images/4.jpg)`
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Just pushed this changes on git and still have same problem.
0

Try this :

getDescriptionBackgroundImg() {
    return `url(assets/images/4.jpg)`
  }

<header [ngStyle]="{'background-image': getDescriptionBackgroundImg(), 'background-position' : 'center', 'height' : '950px', 'width' : '100%'}" class="main__container"></header>

1 Comment

It was just a type mistake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.