Created
July 5, 2021 10:06
-
-
Save Purecaesar/880908c5475c9354c208ef1269195d7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ActivatedRoute } from "@angular/router"; | |
export function getRouteWithData(route: ActivatedRoute, fieldName: string, propagation: boolean): ActivatedRoute { | |
do { | |
if (fieldName in route.snapshot.data) return route; | |
route = route.parent; | |
} while (route && propagation); | |
if (propagation) throw new Error(`Field ${fieldName} didn't find in route tree`); | |
throw new Error (`Field ${fieldName} didn't find in current route`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment