Property '$routeConfig' does not exist on type '($router: any) => void'

1.5k views Asked by At

I am trying to use the angular new router in v1.4. I am using Typescript. When I try to compile, I get the following error.

Property '$routeConfig' does not exist on type '($router: any) => void'

This is my code

 /// <reference path="../Scripts/typings/angularjs/angular.d.ts"/>
/// <reference path="../Scripts/typings/angularjs/angular-route.d.ts"/>
module Application {
    "use strict";
    angular.module("app", ['ngNewRouter']);
    export var getModule: () => ng.IModule = () => {
        return angular.module("app");
    }

    getModule().controller('AppController', ['$router', AppController]);

    AppController.$routeConfig = [{
        path: '/',
        component: 'home'
    }, {
            path: '/detail/:id',
            component: 'detail'
        }, {
            path: '/login',
            component: 'login'
        }];

    function AppController($router) {

    }

}

Any help is appreciated. Thanks.

2

There are 2 answers

0
Muthukumar On BEST ANSWER

I made it work somehow. Following is the code. Now the new route compiles and works without any error.

/// <reference path="../Scripts/typings/angularjs/angular.d.ts"/>
/// <reference path="../Scripts/typings/angularjs/angular-route.d.ts"/>
module Application {
    "use strict";
    angular.module("app", ['ngNewRouter']);
    export var getModule: () => ng.IModule = () => {
        return angular.module("app");
    }

    var AppController: any, $routeConfig: any;

    getModule().controller('AppController', ['$router', AppController = ($router) => {    }]);

    AppController.$routeConfig = [
        {
            path: '/',
            component: 'home'
        },
        {
            path: '/detail/:id',
            component: 'detail'
        },
        {
            path: '/login',
            component: 'login'
        }];
}
1
wjohnsto On

You have a couple options, either use a module or a class.

The module route:

module AppController {
    export let $routeConfig = [{
        path: '/',
        component: 'home'
    }, {
        path: '/detail/:id',
        component: 'detail'
    }, {
        path: '/login',
        component: 'login'
    }];
}

function AppController($router) {

}

and the class route:

class AppController {
    static $routeConfig = [{
        path: '/',
        component: 'home'
    }, {
        path: '/detail/:id',
        component: 'detail'
    }, {
        path: '/login',
        component: 'login'
    }];

    constructor($router) {

    }
}

Depending upon your needs, use whichever works best for you.