vsternbach / tasks-playground

A sample task manager application
https://tasks-162620.firebaseapp.com
1 stars 1 forks source link

Routing doesn't work #2

Open palenshus opened 7 years ago

palenshus commented 7 years ago

In main.ts:28, the code attempts to get the state.component.selector property, which doesn't (any longer?) exist. I worked around this by doing the following, but it sure would be nice if the workaround wasn't needed. (And save people a LOT of hours!)

import "reflect-metadata";
...
export interface IComponentState extends ng.ui.IState {
    componentClass: any;
}
...
const routes: IComponentState[] = [
    { name: "home", url: "/", componentClass: RootComponent }
];
...
    private static provideStates(states: IComponentState[], $stateProvider: ng.ui.IStateProvider) {
        states.map((config) => {

            // Set component name by reflecting metadata from component's @Component decorator
            const componentName = Reflect.getMetadata("custom:name", config.componentClass);
            config.component = componentName;
            delete config.componentClass;

            return { name: config.name, config };
        }).forEach(state => $stateProvider.state(state.name, state.config));
    }
vsternbach commented 7 years ago

Hi, routing is not in use in this example, it's just leftovers of my attempt to decorate ui-router. Btw, there was already one issue on this, so it could save you some time) I'll update the example and remove the router

palenshus commented 7 years ago

Ah, that's a shame, I like the idea of it, it was just a little broken. Adding @arunagiritm for the workaround if you still need it.

vsternbach commented 7 years ago

I thought that it could be problematic to decorate ui-router to comply with angular 2 component router syntax, since their apis and the level of integration into angular application are quite different, so I've decided not to proceed with it. Anyway thanx, it's nice that you've come up with the workaround, you can make a pull request and I'll update it the example, beside I can check later if it's feasible to move this solution into angular-ts-decorators or a standalone npm module for decorating ui-router.