0

Is it ok to do this :

.controller('ComputeCtrl', function($scope, $ionicPopup, $timeout, sessionService) {...})

or we should better write the dependencies like this :

.controller('ComputeCtrl', ['$scope', '$ionicPopup', '$timeout', 'sessionService', function($scope, $ionicPopup, $timeout, sessionService) {...}])

In the ionic starter app, the first version is used.

Thanks

2 Answers 2

2

The second syntax is used, when you want to minify your code. Because the variable names get renamed from $scope to something like a, angularjs won't be able to determine, which module you want to inject. Because of that, you provide a string that tells angular, which module do you want.

If you don't want to minify your code, you can safely use the first syntax.

If you don't like the second syntax, but you want to minify your code, you can use ngAnnotate https://github.com/olov/ng-annotate which will add the annotations for the second syntax on build time (maybe along with grunt-ng-annotate https://www.npmjs.org/package/grunt-ng-annotate).

Sign up to request clarification or add additional context in comments.

Comments

0

Since the seed project is not using minification stuff, it is fine written in first way.

But if you are considering minification make sure you use second version.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.