You can no longer use spaces like this: element.classes.add('foo bar')
Angular users need to update to upcoming bugfix release 1.1.2.
In 1.10 CssClassSet operations will be more strict in their arguments. Arguments to add, remove, contains and toggle must betokens, which are non-empty strings containing no whitespace characters, i.e. a single class name. The collection-based operations like addAll take Iterables containing tokens.
This will now cause an exception to be thrown:
element.classes.addAll('foo bar'.split(' ').where((s) => s.isNotEmpty);
The change was motivated by two factors:
- The operations were incorrect for strings containing spaces. I think it was an oversight that the token restriction was not enforced from the initial implementation of CssClassSet.
- We have customers with performance sensitive code worried about CssClassSet operations showing up too high in their profiles.
We can't fix both of these problems at the same time. We could split and sanitize the string, making all operations slower, or we could adopt arguments that are allowable on HTML5 DOMTokenList operations . This excludes empty strings and strings with spaces.
Had we instead chosen to support spaces, we would be locked into a ~10x performance penalty. I think we all want to avoid this.