From b76cc967a5feb0ea2f0b17d6e51cb38f43b27c00 Mon Sep 17 00:00:00 2001 From: Elad Bezalel Date: Sat, 18 Nov 2017 18:05:25 +0200 Subject: [PATCH] fix(directionality): change event now emit the new value --- src/cdk/bidi/dir.ts | 4 ++-- src/cdk/bidi/directionality.spec.ts | 12 ++++++++---- src/cdk/bidi/directionality.ts | 2 +- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/cdk/bidi/dir.ts b/src/cdk/bidi/dir.ts index cd4afa11570e..77849e83e061 100644 --- a/src/cdk/bidi/dir.ts +++ b/src/cdk/bidi/dir.ts @@ -34,7 +34,7 @@ export class Dir implements Directionality { private _isInitialized: boolean = false; /** Event emitted when the direction changes. */ - @Output('dirChange') change = new EventEmitter(); + @Output('dirChange') change = new EventEmitter(); /** @docs-private */ @Input('dir') @@ -43,7 +43,7 @@ export class Dir implements Directionality { let old = this._dir; this._dir = v; if (old !== this._dir && this._isInitialized) { - this.change.emit(); + this.change.emit(this._dir); } } diff --git a/src/cdk/bidi/directionality.spec.ts b/src/cdk/bidi/directionality.spec.ts index e56308da090c..5d39a20b70eb 100644 --- a/src/cdk/bidi/directionality.spec.ts +++ b/src/cdk/bidi/directionality.spec.ts @@ -1,7 +1,7 @@ -import {async, fakeAsync, TestBed, tick} from '@angular/core/testing'; +import {async, fakeAsync, TestBed} from '@angular/core/testing'; import {Component} from '@angular/core'; import {By} from '@angular/platform-browser'; -import {BidiModule, Directionality, DIR_DOCUMENT} from './index'; +import {BidiModule, Directionality, Direction, DIR_DOCUMENT} from './index'; describe('Directionality', () => { let fakeDocument: FakeDocument; @@ -62,14 +62,18 @@ describe('Directionality', () => { fixture.detectChanges(); + let direction = injectedDirectionality.value; + injectedDirectionality.change.subscribe((dir: Direction) => { direction = dir; }); + + expect(direction).toBe('rtl'); expect(injectedDirectionality.value).toBe('rtl'); expect(fixture.componentInstance.changeCount).toBe(0); fixture.componentInstance.direction = 'ltr'; fixture.detectChanges(); - tick(); + expect(direction).toBe('ltr'); expect(injectedDirectionality.value).toBe('ltr'); expect(fixture.componentInstance.changeCount).toBe(1); })); @@ -79,7 +83,7 @@ describe('Directionality', () => { @Component({ template: ` -
+
` diff --git a/src/cdk/bidi/directionality.ts b/src/cdk/bidi/directionality.ts index 8bb96ed61337..195e4d3c8d7b 100644 --- a/src/cdk/bidi/directionality.ts +++ b/src/cdk/bidi/directionality.ts @@ -39,7 +39,7 @@ export class Directionality { readonly value: Direction = 'ltr'; /** Stream that emits whenever the 'ltr' / 'rtl' state changes. */ - readonly change = new EventEmitter(); + readonly change = new EventEmitter(); constructor(@Optional() @Inject(DIR_DOCUMENT) _document?: any) { if (_document) {