Reputation: 34099
I am trying to use ng-annotate on my angular application but does not work at all.
I have configuration part:
(function () {
'use strict';
angular.module('app')
.config(/*@ngInject*/ routes);
function routes ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
url: '/',
templateUrl: 'app/main/view.html',
controller: 'MainCtrl'
});
$stateProvider
.state('signup', {
url: '/signup',
templateUrl: 'app/signup/view.html',
controller: 'SignUpCtrl'
});
$urlRouterProvider.otherwise('/');
}
})();
and when I run angular app, then I've got the error message:
Error: [$injector:modulerr] Failed to instantiate module app due to:
[$injector:strictdi] routes is not using explicit annotation and cannot be invoked in strict mode
http://errors.angularjs.org/1.3.15/$injector/strictdi?p0=routes
and the ng-annotate is implemented in my gulp config file:
gulp.task('html', ['inject', 'partials'], function () {
var partialsInjectFile = gulp.src(options.tmp + '/partials/templateCacheHtml.js', { read: false });
var partialsInjectOptions = {
starttag: '<!-- inject:partials -->',
ignorePath: options.tmp + '/partials',
addRootSlash: false
};
var htmlFilter = $.filter('*.html');
var jsFilter = $.filter('**/*.js');
var cssFilter = $.filter('**/*.css');
var assets;
return gulp.src(options.tmp + '/serve/*.html')
.pipe($.inject(partialsInjectFile, partialsInjectOptions))
.pipe(assets = $.useref.assets())
.pipe($.rev())
.pipe(jsFilter)
.pipe($.ngAnnotate())
.pipe($.uglify({ preserveComments: $.uglifySaveLicense })).on('error', options.errorHandler('Uglify'))
.pipe(jsFilter.restore())
.pipe(cssFilter)
.pipe($.csso())
.pipe(cssFilter.restore())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe(htmlFilter)
.pipe($.minifyHtml({
empty: true,
spare: true,
quotes: true,
conditionals: true
}))
.pipe(htmlFilter.restore())
.pipe(gulp.dest(options.dist + '/'))
.pipe($.size({ title: options.dist + '/', showFiles: true }));
});
What am I doing wrong?
Upvotes: 0
Views: 1076
Reputation: 391
Run your example through ng-annotate -a example.js
(npm install -g ng-annotate
first) and you'll see that routes is properly annotated. You can skip the /*@ngInject*/
comment for it if you want to, it's not needed.
I'd guess that your problem is that you're doing controller: 'MainCtrl'
instead of controller: MainCtrl
. ng-annotate has no way of following the reference if it's a string literal so change it or make sure to do an explicit ngInject on MainCtrl itself.
Upvotes: 1