diff --git a/src/ng/directive/ngClass.js b/src/ng/directive/ngClass.js index 664e4810ce21..fc7b6db2c032 100644 --- a/src/ng/directive/ngClass.js +++ b/src/ng/directive/ngClass.js @@ -125,6 +125,8 @@ function classDirective(name, selector) { } function toClassString(classValue) { + if (!classValue) return classValue; + var classString = classValue; if (isArray(classValue)) { @@ -133,6 +135,8 @@ function classDirective(name, selector) { classString = Object.keys(classValue). filter(function(key) { return classValue[key]; }). join(' '); + } else if (!isString(classValue)) { + classString = classValue + ''; } return classString; diff --git a/test/ng/directive/ngClassSpec.js b/test/ng/directive/ngClassSpec.js index 0180d67a6aa4..74500505fd84 100644 --- a/test/ng/directive/ngClassSpec.js +++ b/test/ng/directive/ngClassSpec.js @@ -88,6 +88,12 @@ describe('ngClass', function() { expect(element.hasClass('AnotB')).toBeFalsy(); })); + it('should not break when passed non-string/array/object, truthy values', inject(function($rootScope, $compile) { + element = $compile('
')($rootScope); + $rootScope.$digest(); + expect(element.hasClass('42')).toBeTruthy(); + })); + it('should support adding multiple classes via an array mixed with conditionally via a map', inject(function($rootScope, $compile) { element = $compile('')($rootScope); $rootScope.$digest();