简体   繁体   中英

What is the difference between these two angular js controllers?

When declaring a controller I usually see these:

University.controller('ClassroomController', function($scope){
//do stuff
});

What's the difference of it compared to:

var classroomController = function ($scope){
//do stuff
}

University.controller('ClassroomController',['$scope',classroomController])

The tutorials doesn't seem to say whats the advantage of the second type of declaration.

The first syntax will break if you minify your js. Angular will for exemple try to find $timeout but will find a

To prevent that, you have to declare explicitly or inline your dependencies

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM