How to change the body background or background-color on route change, angular 4?
Asked
Active
Viewed 1,869 times
3
-
1What 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
-
2That'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 Answers
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
-
so even though this question has been answered I should copy that answer into here? – LoganRx Aug 13 '17 at 22:14
-
You could propose it as a duplicate, and let the OP spend some figuring out how to adapt it to their specific needs. – jonrsharpe Aug 13 '17 at 22:17