Understanding dependency injection in AngularJS controllers
问题 Just learning dependency injection, and I think I'm starting to understand it. Please tell me if I'm on the right track... E.g.: Are these two equivalent? /* injection method */ function <controller_name>($scope) {} <controller_name>.$inject = ['$scope']; /* other method */ var app = angular.module('myApp'); app.controller(<controller_name>, function($scope) {}); 回答1: First a little clarification: For dependency injection, it doesn't matter whether you declare a controller using a global