ERROR in Can not read property 'loadChildren' of undefined

1

Good morning, does anyone know how to solve this problem that I have about angula routing?

What I want to do is: As my object to create a new route in angular became something complex, I wanted to put it in an interface, then in the constructor of that object I could do common things for all the objects that I create in the app .route.ts

When implementing my interface, which does absolutely nothing complex, the compiler gives me the error: ERROR in Can not read property 'loadChildren' of undefined

Here the code that does go, without implementing my interface (I repeat, this if it goes, and it does not bring me any problem):

app.route.ts:

const APP_ROUTES = [
    {path: 'rolListado', component: RolListadoComponent, canActivate: [RouteFilterService], data: {rolesHabilitados: [Shared.ROL_ADMIN]}},
];

export const APP_ROUTING = RouterModule.forRoot(APP_ROUTES, {useHash: true});

This is what I wanted to implement that does not work for me and generates the error mentioned above. That would be the same but with an interface:

app.route.ts:

const APP_ROUTES: Routes = [
    new Ruta('rolListado', RolListadoComponent),
];

export const APP_ROUTING = RouterModule.forRoot(APP_ROUTES, {useHash: true});

ruta.interfaz.ts:

export class Ruta {

    path;
    component;
    canActivate;
    data;

    constructor(path, component, roles?) {
        this.path = path;
        this.component = component;
        this.canActivate = [RouteFilterService];
        this.data = {rolesHabilitados: [Shared.ROL_ADMIN]};
        if (roles) {
            this.data.rolesHabilitados.concat(roles);
        }
    }
}

Here is a catch of the error:

I wanted to implement this interface because as I have many routes the code was very much, the app.route.ts was left with a lot of code that one saw that is repeated in all the routes that one is adding

It is worth mentioning that I am using the latest version of angular

Can you think of a solution to fix this problem? Thank you in advance

Pd: I have nowhere in the project a class or property called "loadChildren", I'm completely sure. I have made a find in the whole project and no coincidence. And I never created a class or property with that name

    
asked by Martin 12.10.2018 в 15:23
source

0 answers