Why do angularjs controller declaration have this syntax structure?

后端 未结 5 1948
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-27 23:55

I see the following angularjs controller syntax structure all the time.

angular.module(\'7minWorkout\').controller(\'WorkoutController\', 
[\'$scope\', \'$in         


        
5条回答
  •  执念已碎
    2020-11-28 00:18

    The first controller syntax makes it possible to minify/uglify the javascript code with the use of tools like ngmin. I'm not quite sure if the 2nd and 3rd options you have provided are viable options to create a controller, but in any case they will not be minified correctly since the tools will not now what the providers are. I would either suggest to use option 1 or option 3 (without the brackets) to create a controller. Note that option 3 will not be minified correctly by automated tools.

    Some Useful information about creating controllers: AngularJS Developer Guide - Controllers

    option3 without brackets

    angular.module('7minWorkout').controller('WorkoutController', function ($scope, $interval, $location)
        {
          //Your Code
        });
    

提交回复
热议问题