diff --git a/src/core/services/theming/theming.js b/src/core/services/theming/theming.js index 80cda760ecb..995dd66096f 100644 --- a/src/core/services/theming/theming.js +++ b/src/core/services/theming/theming.js @@ -282,7 +282,7 @@ function ThemingProvider($mdColorPalette) { * @param {el=} element to apply theming to */ /* @ngInject */ - function ThemingService($rootScope) { + function ThemingService($rootScope, $log) { applyTheme.inherit = function(el, parent) { var ctrl = parent.controller('mdTheme'); @@ -298,6 +298,10 @@ function ThemingProvider($mdColorPalette) { } function changeTheme(theme) { + if (!registered(name)) { + debugger; + $log.warn('attempted to use unregistered theme \'' + theme + '\''); + } var oldTheme = el.data('$mdThemeName'); if (oldTheme) el.removeClass('md-' + oldTheme +'-theme'); el.addClass('md-' + theme + '-theme'); @@ -305,8 +309,15 @@ function ThemingProvider($mdColorPalette) { } }; + applyTheme.registered = registered; + return applyTheme; + function registered(theme) { + if (theme === undefined || theme === '') return true; + return THEMES[theme] !== undefined; + } + function applyTheme(scope, el) { // Allow us to be invoked via a linking function signature. if (el === undefined) { @@ -321,13 +332,16 @@ function ThemingProvider($mdColorPalette) { } } -function ThemingDirective($interpolate) { +function ThemingDirective($mdTheming, $interpolate, $log) { return { priority: 100, link: { pre: function(scope, el, attrs) { var ctrl = { $setTheme: function(theme) { + if (!$mdTheming.registered(theme)) { + $log.warn('attempted to use unregistered theme \'' + theme + '\''); + } ctrl.$mdTheme = theme; } }; diff --git a/src/core/services/theming/theming.spec.js b/src/core/services/theming/theming.spec.js index b106aacf585..2b4e3535d94 100644 --- a/src/core/services/theming/theming.spec.js +++ b/src/core/services/theming/theming.spec.js @@ -35,6 +35,7 @@ describe('$mdThemingProvider', function() { .backgroundPalette('testPalette'); testTheme = themingProvider.theme('test'); + }); startAngular(); } @@ -361,6 +362,15 @@ describe('md-theme directive', function() { $rootScope.$apply('themey = "blue"'); expect(ctrl.$mdTheme).toBe('blue'); })); + + it('warns when an unregistered theme is used', function() { + inject(function($log, $compile, $rootScope) { + spyOn($log, 'warn'); + var el = $compile('
')($rootScope); + $rootScope.$apply(); + expect($log.warn).toHaveBeenCalled(); + }); + }); }); describe('md-themable directive', function() {