Navin Chinnasamy Navin Chinnasamy - 3 months ago 10
AngularJS Question

Get angularjs controller of current html page

How can I get the controller of the current page that is displayed on device? I just want to add a class named as controller name of that page. So that I can customize that page dynamically.

Answer

Do like this :

app.run(function($rootScope) {
    $rootScope.$on('$routeChangeSuccess', function(ev,data) {   
       if (data.$route && data.$route.controller)
    $rootScope.controller = data.$route.controller;
    })
});