1

So I was using this website to show me the basics: https://www.codeproject.com/Articles/1130132/Learn-AngularJS-for-Beginners

and on the scope inheritance section I was thrown off because of the controller used for that example compared to the example controller used as intro to controllers.

what is the difference between:

app.controller("PersonController", function($scope) {
    $scope.employeeData = personData;
    $scope.employeeMethod = function() {
      console.log("Hello, I am an Employee");
    }
});

and

app.controller("MainController", ['$scope', function($scope){
    $scope.name = "Donald"; 
    $scope.color = "White";
}]);

as in the first one is name then function, the second is name then bracket.

4

1 Answer 1

0

from here implicit annotation assumes function params to be name of the services

someModule.controller('MyController', function($scope, greeter) {
  // ...
});

$scope and greeter are the names of services above.

So both DI techniques work the same way except when some JavaScript minifiers/obfuscators are used because they can rename function parameters but not the inline Array.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.