I see several way to log infos from/of the controller.
1) using element.controller()
From the docs of element.controller()
:
controller(name)
- retrieves the controller of the current element or its parent. By default retrieves controller associated with
the ngController directive. If name
is provided as camelCase
directive name, then the controller for this directive will be
retrieved (e.g. 'ngModel'
).
You can this function on very element to get its parent controller. Here is an snippet example using a directive:
var app = angular.module('app', [])
app.controller('MainController', function MainController() {});
app.controller('directiveCtrl', function directiveCtrl() {});
app.directive('controllerName', function($timeout) {
return {
restrict: 'A',
template: '<div>My controller name is: {{cName}}</div>',
controller: 'directiveCtrl',
link: function($scope, elem, attrs) {
var name;
name = elem.controller().constructor.name;
$scope.cName = name;
}
};
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<div ng-app="app">
<div ng-controller="MainController">
<div controller-name></div>
</div>
***************************************************
<div ng-controller="MainController">
<div ng-controller="directiveCtrl">
<div controller-name></div>
</div>
</div>
<hr/>
</div>
2) using the console
You can access to every Angular object from your web console. For example, typing angular.element($0).scope()
will get the current scope.
See this answer, which is very complete about the use of the console.
3) logging from the controller
You can add a console call in your controller at the beginning of the code, and log whatever you want. This way, you will know each time a controller is instanciated:
app.controller('MyCtrl', function($scope) {
$scope.greetings = 'Hello world';
console.log('MyCtrl instanciated!', $scope.greetings);
});