fix(ng_class): support sets correctly

Previously, NgClass threw in Dart checked mode.

Closes #4910
This commit is contained in:
Tobias Bosch
2015-10-26 09:50:51 -07:00
parent 28db864690
commit 2957b0b32e
2 changed files with 33 additions and 4 deletions

View File

@ -1,4 +1,4 @@
import {isPresent, isString, StringWrapper, isBlank} from 'angular2/src/core/facade/lang';
import {isPresent, isString, StringWrapper, isBlank, isArray} from 'angular2/src/core/facade/lang';
import {DoCheck, OnDestroy} from 'angular2/lifecycle_hooks';
import {Directive} from 'angular2/src/core/metadata';
import {ElementRef} from 'angular2/src/core/linker';
@ -146,10 +146,13 @@ export class NgClass implements DoCheck, OnDestroy {
this._initialClasses.forEach(className => this._toggleClass(className, !isCleanup));
}
private _applyClasses(rawClassVal: string[] | {[key: string]: string}, isCleanup: boolean) {
private _applyClasses(rawClassVal: string[] | Set<string>| {[key: string]: string},
isCleanup: boolean) {
if (isPresent(rawClassVal)) {
if (isListLikeIterable(rawClassVal)) {
if (isArray(rawClassVal)) {
(<string[]>rawClassVal).forEach(className => this._toggleClass(className, !isCleanup));
} else if (rawClassVal instanceof Set) {
(<Set<string>>rawClassVal).forEach(className => this._toggleClass(className, !isCleanup));
} else {
StringMapWrapper.forEach(<{[k: string]: string}>rawClassVal, (expVal, className) => {
if (expVal) this._toggleClass(className, !isCleanup);