src/core/services/theming/theming.js
function inheritTheme (el, parent) {
      var ctrl = parent.controller('mdTheme') || el.data('$mdThemeController');
      var scope = el.scope();

      updateThemeClass(lookupThemeName());

      if (ctrl) {
        var watchTheme = alwaysWatchTheme ||
                         ctrl.$shouldWatch ||
                         $mdUtil.parseAttributeBoolean(el.attr('md-theme-watch'));

        if (watchTheme || ctrl.isAsyncTheme) {
          var clearNameWatcher = function () {
            if (unwatch) {
              unwatch();
              unwatch = undefined;
            }
          };

          var unwatch = ctrl.registerChanges(function(name) {
            updateThemeClass(name);

            if (!watchTheme) {
              clearNameWatcher();
            }
          });

          if (scope) {
            scope.$on('$destroy', clearNameWatcher);
          } else {
            el.on('$destroy', clearNameWatcher);
          }
        }
      }

      /**
       * Find the theme name from the parent controller or element data
       */
      function lookupThemeName() {
        // As a few components (dialog) add their controllers later, we should also watch for a controller init.
        return ctrl && ctrl.$mdTheme || (defaultTheme === 'default' ? '' : defaultTheme);
      }

      /**
       * Remove old theme class and apply a new one
       * NOTE: if not a valid theme name, then the current name is not changed
       */
      function updateThemeClass(theme) {
        if (!theme) return;
        if (!registered(theme)) {
          $log.warn('Attempted to use unregistered theme \'' + theme + '\'. ' +
                    'Register it with $mdThemingProvider.theme().');
        }

        var oldTheme = el.data('$mdThemeName');
        if (oldTheme) el.removeClass('md-' + oldTheme +'-theme');
        el.addClass('md-' + theme + '-theme');
        el.data('$mdThemeName', theme);
        if (ctrl) {
          el.data('$mdThemeController', ctrl);
        }
      }
    }
function inheritTheme (el, parent) {
      var ctrl = parent.controller('mdTheme') || el.data('$mdThemeController');
      var scope = el.scope();

      updateThemeClass(lookupThemeName());

      if (ctrl) {
        var watchTheme = alwaysWatchTheme ||
                         ctrl.$shouldWatch ||
                         $mdUtil.parseAttributeBoolean(el.attr('md-theme-watch'));

        if (watchTheme || ctrl.isAsyncTheme) {
          var clearNameWatcher = function () {
            if (unwatch) {
              unwatch();
              unwatch = undefined;
            }
          };

          var unwatch = ctrl.registerChanges(function(name) {
            updateThemeClass(name);

            if (!watchTheme) {
              clearNameWatcher();
            }
          });

          if (scope) {
            scope.$on('$destroy', clearNameWatcher);
          } else {
            el.on('$destroy', clearNameWatcher);
          }
        }
      }

      /**
       * Find the theme name from the parent controller or element data
       */
      function lookupThemeName() {
        // As a few components (dialog) add their controllers later, we should also watch for a controller init.
        return ctrl && ctrl.$mdTheme || (defaultTheme === 'default' ? '' : defaultTheme);
      }

      /**
       * Remove old theme class and apply a new one
       * NOTE: if not a valid theme name, then the current name is not changed
       */
      function updateThemeClass(theme) {
        if (!theme) return;
        if (!registered(theme)) {
          $log.warn('Attempted to use unregistered theme \'' + theme + '\'. ' +
                    'Register it with $mdThemingProvider.theme().');
        }

        var oldTheme = el.data('$mdThemeName');
        if (oldTheme) el.removeClass('md-' + oldTheme +'-theme');
        el.addClass('md-' + theme + '-theme');
        el.data('$mdThemeName', theme);
        if (ctrl) {
          el.data('$mdThemeController', ctrl);
        }
      }
    }
function inheritTheme ( el , parent ) { var ctrl = parent . controller ( 'mdTheme' ) || el . data ( '$mdThemeController' ) ; var scope = el . scope ( ) ; updateThemeClass ( lookupThemeName ( ) ) ; if ( ctrl ) { var watchTheme = alwaysWatchTheme || ctrl . $shouldWatch || $mdUtil . parseAttributeBoolean ( el . attr ( 'md-theme-watch' ) ) ; if ( watchTheme || ctrl . isAsyncTheme ) { var clearNameWatcher = function ( ) { if ( unwatch ) { unwatch ( ) ; unwatch = undefined ; } } ; var unwatch = ctrl . registerChanges ( function ( name ) { updateThemeClass ( name ) ; if ( ! watchTheme ) { clearNameWatcher ( ) ; } } ) ; if ( scope ) { scope . $on ( '$destroy' , clearNameWatcher ) ; } else { el . on ( '$destroy' , clearNameWatcher ) ; } } } /**
       * Find the theme name from the parent controller or element data
       */ function lookupThemeName ( ) { // As a few components (dialog) add their controllers later, we should also watch for a controller init. return ctrl && ctrl . $mdTheme || ( defaultTheme === 'default' ? '' : defaultTheme ) ; } /**
       * Remove old theme class and apply a new one
       * NOTE: if not a valid theme name, then the current name is not changed
       */ function updateThemeClass ( theme ) { if ( ! theme ) return ; if ( ! registered ( theme ) ) { $log . warn ( 'Attempted to use unregistered theme \'' + theme + '\'. ' + 'Register it with $mdThemingProvider.theme().' ) ; } var oldTheme = el . data ( '$mdThemeName' ) ; if ( oldTheme ) el . removeClass ( 'md-' + oldTheme + '-theme' ) ; el . addClass ( 'md-' + theme + '-theme' ) ; el . data ( '$mdThemeName' , theme ) ; if ( ctrl ) { el . data ( '$mdThemeController' , ctrl ) ; } } }
Get theme name for the element, then update with Theme CSS class
Get theme name for the element then update with Theme CSS class