Syntax query not Angular

1

I'm starting in Angular and in some cases I saw that parameters are passed in the bracket of the module and in other cases in the function, and in the function I have already seen 2 forms of declaration.

Example Module:

angular.module('starter', ['ionic', 'starter.controllers', 'starter.services', 'ui.utils.masks', 'ngCordova', 'angular-md5', 'ngMessages', 'angularSoap'])

Example Function 1:

.config(function ($stateProvider, $urlRouterProvider, $ionicConfigProvider){...}

.controller('LoginCtrl', function ($scope, $rootScope, $pouchDB){...}

Example Function 2:

.controller('GreetingController', ['$scope, $any', function($scope, $any){...}

Someone could explain me:

  • What is the difference between the declaration of Function 1 and Function 2 (why do these two forms exist and what would be the practical impact in choosing one or the other)?
  • What is the difference between passing these parameters on the module and on the functions?
    • Are there any links between them?
  • What is happening and what can happen in these parameters

Do not just stick to my questions. The more information, the better, but at first my doubts are these above.

    
asked by anonymous 21.07.2016 / 16:46

1 answer

2
  • What is the difference between the declaration of Function 1 and Function 2 (why do these two forms exist and what would be the practical impact in choosing one or the other)?

When minimizing JavaScript files, parameter names are changed to shorter names $ scope = > The. When the mangle function is enabled, ['$scope',function($scope){}] must be used in this format, so Angular recognizes the parameter to be injected into the controller.

  • What is the difference between passing these parameters on the module and on the functions? Are there any links between them?

The parameters in the module are exactly what external dependencies the module should load. Ex: app.module('myApp',['ngResource']).controller('AppCtrl',['$scope','$resource',function($scope, $resource))

In the above example I load the ngResource module so I can use it in my controllers.

Any questions, just talk.

    
21.07.2016 / 18:16