3

How to change the body background or background-color on route change, angular 4?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
  • 1
    What have you tried so far, and what exactly is the problem with it? – jonrsharpe Aug 13 '17 at 22:04
  • I need to change the background color from the main index.html when I route to home component or dashboard component – Maik Fields Aug 13 '17 at 22:08
  • 2
    That's your *requirement*, not what you've *actually tried*. Please note that SO is not a code-writing or tutorial service; take the [tour] and review [ask]. – jonrsharpe Aug 13 '17 at 22:08
  • Code is text, **post it as such**. Screenshots are useless. Give a [mcve], and spend some more time reviewing the material in the [help]. Ensure that you're demonstrating actual research effort, not just more detail on what you want other people to implement for you. – jonrsharpe Aug 13 '17 at 22:20

1 Answers1

2

Just need to listen for the route change event, which should be NavigationEnd, also may want to check this post out and do something like:

document.body.style.background = '#000' // or whatever color
LoganRx
  • 362
  • 2
  • 13