Angular -JS strict-DI does not like to enter allowed results from $ routeProvider

I hit some problems by reducing my Angular code, so I included ng-strict-di

One problem seems to be how I resolve the promise along the route in my app.js configuration

.when('/:userId', {
           templateUrl: 'views/main.html', 
           controller: 'MyCtrl',  
           resolve : {
               myDependency : function(Cache, Model, $route){ 
                  return Cache.getCached( $route.current.params.userId); 
               } 
           }
      })

Then I insert this resolved promise into the MyCtrl controller

angular.module('myApp') 
    .controller('MyCtrl',[ 'myDependency',  '$scope', '$rootScope', '$timeout', function (myDependency, $scope, $rootScope, $timeout) { 
 etc... 

However, I get an Angular error message

[Error] Error: [$injector:strictdi] myDependency is not using explicit annotation and cannot be invoked in strict mode 

The problem seems to be traced to the resolution definition in app.js, because I can change the name "myDependency" there in the solution, and the error message uses the name from there, and not the dependency name in myCtrl. And I explicitly list the dependency name in myCtrl controller. The application works, but I can not minimize this code due to a problem with this error.

+4
2

. , !

resolve : {
           myDependency : ['Cache', 'Model', '$route', function(Cache, Model, $route){ 
               return Cache.getCached( $route.current.params.userId); 
           } 
     ]}
+5

, @Mahesh Sapkal .

, , ng-annotate , . /@ngInject/comment, !

app.config(/*@ngInject*/function ($routeProvider) {
    $routeProvider
        .when('/tables', {
            template: templateList,
            controller: 'TableListController',
            resolve: {
                initial: /*@ngInject*/function (tableListControllerInitial) {
                    return tableListControllerInitial();
                }
            }
        })
0

All Articles