parent
f1e4292072
commit
1438922ffb
|
@ -28,8 +28,11 @@ import {ListWrapper, StringMapWrapper, isListLikeIterable} from 'angular2/src/fa
|
||||||
* </div>
|
* </div>
|
||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
@Directive(
|
@Directive({
|
||||||
{selector: '[class]', lifecycle: [LifecycleEvent.onCheck], properties: ['rawClass: class']})
|
selector: '[class]',
|
||||||
|
lifecycle: [LifecycleEvent.onCheck, LifecycleEvent.onDestroy],
|
||||||
|
properties: ['rawClass: class']
|
||||||
|
})
|
||||||
export class CSSClass {
|
export class CSSClass {
|
||||||
_pipe: Pipe;
|
_pipe: Pipe;
|
||||||
_rawClass;
|
_rawClass;
|
||||||
|
@ -58,6 +61,8 @@ export class CSSClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onDestroy(): void { this._cleanupClasses(this._rawClass); }
|
||||||
|
|
||||||
private _cleanupClasses(rawClassVal): void {
|
private _cleanupClasses(rawClassVal): void {
|
||||||
if (isPresent(rawClassVal)) {
|
if (isPresent(rawClassVal)) {
|
||||||
if (isListLikeIterable(rawClassVal)) {
|
if (isListLikeIterable(rawClassVal)) {
|
||||||
|
|
|
@ -14,13 +14,36 @@ import {
|
||||||
xit,
|
xit,
|
||||||
} from 'angular2/test_lib';
|
} from 'angular2/test_lib';
|
||||||
import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
import {List, ListWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||||
import {Component, View} from 'angular2/angular2';
|
import {Component, View, NgFor, bind} from 'angular2/angular2';
|
||||||
import {DOM} from 'angular2/src/dom/dom_adapter';
|
import {DOM} from 'angular2/src/dom/dom_adapter';
|
||||||
import {CSSClass} from 'angular2/src/directives/class';
|
import {CSSClass} from 'angular2/src/directives/class';
|
||||||
|
import {APP_VIEW_POOL_CAPACITY} from 'angular2/src/core/compiler/view_pool';
|
||||||
|
|
||||||
export function main() {
|
export function main() {
|
||||||
describe('binding to CSS class list', () => {
|
describe('binding to CSS class list', () => {
|
||||||
|
|
||||||
|
describe('viewpool support', () => {
|
||||||
|
beforeEachBindings(() => { return [bind(APP_VIEW_POOL_CAPACITY).toValue(100)]; });
|
||||||
|
|
||||||
|
it('should clean up when the directive is destroyed',
|
||||||
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
||||||
|
var template = '<div *ng-for="var item of items" [class]="item"></div>';
|
||||||
|
tcb.overrideTemplate(TestComponent, template)
|
||||||
|
.createAsync(TestComponent)
|
||||||
|
.then((rootTC) => {
|
||||||
|
rootTC.componentInstance.items = [['0']];
|
||||||
|
rootTC.detectChanges();
|
||||||
|
rootTC.componentInstance.items = [['1']];
|
||||||
|
rootTC.detectChanges();
|
||||||
|
expect(rootTC.componentViewChildren[1].nativeElement.className)
|
||||||
|
.toEqual('ng-binding 1');
|
||||||
|
|
||||||
|
async.done();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('expressions evaluating to objects', () => {
|
describe('expressions evaluating to objects', () => {
|
||||||
|
|
||||||
it('should add classes specified in an object literal',
|
it('should add classes specified in an object literal',
|
||||||
|
@ -344,9 +367,10 @@ export function main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({selector: 'test-cmp'})
|
@Component({selector: 'test-cmp'})
|
||||||
@View({directives: [CSSClass]})
|
@View({directives: [CSSClass, NgFor]})
|
||||||
class TestComponent {
|
class TestComponent {
|
||||||
condition: boolean = true;
|
condition: boolean = true;
|
||||||
|
items: any[];
|
||||||
arrExpr: List<string> = ['foo'];
|
arrExpr: List<string> = ['foo'];
|
||||||
objExpr = {'foo': true, 'bar': false};
|
objExpr = {'foo': true, 'bar': false};
|
||||||
strExpr = 'foo';
|
strExpr = 'foo';
|
||||||
|
|
Loading…
Reference in New Issue