gmostert / ng2-breadcrumb

This is an angular 2 component that creates a breadcrumb trail. It hooks into the angular2/router, to dynamically build up the crumb trail once a component is routed to.
MIT License
102 stars 81 forks source link

Really needs to be able to resolve name from params #30

Open nth-commit opened 7 years ago

nth-commit commented 7 years ago

Rather than synchronous callback, it really needs to be able to return an Observable/Promise.

gmostert commented 7 years ago

Yea, def the preferred way, just havent gotten round to it yet. This is what I have in mind though:

Add an @Input binding that expects a function that returns an observable string. Whenever a navigation event is triggered, this input function will be called with the url of the route. Thus its up to the parent app to map its own url/route names in this method and return the result as an observable.

<breadcrumb [routeName]="getRouteName"></breadcrumb>
getRouteName(url:string):Observable<string> {
    return new Observable<string>((observer: Subscriber<string>) => {
        var name:string = '';
        if ('/comp1' == url) {
            name = 'Comp 1';
        } else if (new RegExp('^/comp1/comp[0-9]$').exec(url)) {
            name = 'Comp 2';
        }
        observer.next(name);
    });
}
sascha10000 commented 7 years ago

A few minutes ago I have added the possibility to set Observable as parameter for the methods: addCallbackForRouteRegexObservable addFriendlyNameForRouteRegexObservable

And I have modified the component to use Observable instead of string. It seems to work, but atm Iam testing. I don't know how to properly contribute. If somebody can help me, I can provide my solution.

jeroensneyers commented 7 years ago

+1 If you could share your solution in any way, that would be great.

sascha10000 commented 7 years ago

First basic test worked. If i simply put a string into the observable and used the async pipe. But when I started to put in an Observable comming from an Http-Request, which means having an delay it landed in an endless loop caused by some kind of recursion. The problem here was that I couldn't resolve where the source of the recursion occured. So my solution isn't working. But I will build an own component and share the source. Sorry for that.

MarkDeVerno commented 7 years ago

+1 Any progress on this?

kayleighbray commented 7 years ago

+1 This is much needed

jcmordan commented 7 years ago

+1 waiting for this