ngInject and closure compiler

2019-05-07 11:10发布

I try to compile the following code in ADVANCED mode unsuccessfully:

/**
 * @description App configuration
 * @param {!angular.$routeProvider} $routeProvider
 * @constructor
 * @ngInject
 */
function Config ($routeProvider) {
    $routeProvider
        .when('/', {
            templateUrl: 'mainpage/mainpage.html',
            controller: 'MainpageCtrl'
        })
        .when('/viewer', {
            templateUrl: 'viewer/viewer.html',
            controller: 'ViewerCtrl'
        })
        .otherwise({
            redirectTo: '/'
        });
}

Is there any special flag to be turned on?

If I add the following line it works, but I would like to take advantage of ngInect.

Config['$inject'] = ['$routeProvider'];

Thanks

2条回答
劳资没心,怎么记你
2楼-- · 2019-05-07 11:28

I solved this way :

var app = angular.module("myApp", ['ngRoute']);
app.config(['$routeProvider', Config]);

I am using typescript...

查看更多
迷人小祖宗
3楼-- · 2019-05-07 11:29

The closure compiler needs to run with the "--angular_pass" flag.

查看更多
登录 后发表回答