Issue
I'm trying to change the div class depending on the route (/home)
I thought this would do the trick:
[ngClass]="{'background_image':router.url === '/home'}
But it seems to not have the effect i was looking for..
Will I need to pass the route into a variable and feed it through the ngClass?
I cannot find any solutions online to this issue.
Solution
I would create a getter in to the component .ts file where the boolean value is calculated. For instance:
get isRouteHome(): boolean {
// logic here
this.activatedRoute.url === RouterPaths.home;
}
edit: I forgot that I usually make string enums for my route paths (here: RouterPaths). It is then easier to use those variables across the app.
And in template:
[ngClass]="{'background_image': isRouteHome }"
Answered By - O-9
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.