0

Edit: Thanks to deoD for pointing me to the right place - this is a duplicate of Angularjs minify best practice


I feel like this must be a pretty simple thing, but I don't know the name of it and Googling hasn't turned up much :/

Some Ionic tutorials that I've seen define controllers (and factories, etc) like this to inject a dependency

angular.module( 'x' )
    .controller( 'XController', function( $scope ) {
        // ...
    } );

And some define it like this

angular.module( 'x' )
    .controller( 'XController', [ '$scope',
        function( $scope ) {
            // ...
        }
    ] );

What's the difference between the two, and if that doesn't answer the following question, when would you use one over the other?

Community
  • 1
  • 1
Joe
  • 15,669
  • 4
  • 48
  • 83
  • 1
    this would answer your question - http://stackoverflow.com/questions/18782324/angularjs-minify-best-practice (basically it is best practice for js minification) – Disha Sep 08 '16 at 11:07
  • @deoD thanks - I knew it must have been asked, but since I didn't know what it was trying to solve, I couldn't find it :) Voting to close this since it's a duplicate, thanks – Joe Sep 08 '16 at 11:08
  • 1
    This is basically implicit vs explicit dependency injection; you should only really use implicit injection in quick example snippets, never in live production code. – Claies Sep 08 '16 at 11:10

1 Answers1

0

Actually, you can just go ahead and read more about it on https://docs.angularjs.org/guide/di as Ionic is based on AngularJS.

Using minified version looks simpler and cleaner for me :

 myApp.controller('MainController', function ($scope, $route, $http,$cookies,$timeout){
    //..
 });
Shivan
  • 137
  • 1
  • 9