I recently read in angular documentation (https://code.angularjs.org/1.4.9/docs/guide/providers) this:
myApp.controller('DemoController', ['clientId', function DemoController(clientId) {
this.clientId = clientId;
}]);
associated to:
<html ng-app="myApp">
<body ng-controller="DemoController as demo">
Client ID: {{demo.clientId}}
</body>
</html>
Then I was surprised because this
was used instead of an injected $scope
service.
I tried to reproduce with success, then I'm wondering if someone could explain one use-case where using controller instance is preferable to injected $scope
?