Skip to content
This repository has been archived by the owner on Feb 2, 2019. It is now read-only.

Commit

Permalink
fix(input): work with async value bindings
Browse files Browse the repository at this point in the history
 - add test for async @input() bindings to value.
 - move @input() on to the setter function rather than the internal data member.
 - closes #40, #39, #59
  • Loading branch information
justindujardin committed Feb 21, 2016
1 parent f67e508 commit 0014bc4
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ng2-material/components/input/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ import {DOM} from "angular2/src/platform/dom/dom_adapter";
providers: [FORM_PROVIDERS]
})
export class MdInput {
@Input('value')
_value: string;

@Input('value')
set value(value: string) {
this._value = value;
ObservableWrapper.callEmit(this.mdChange, this.value);
Expand Down
26 changes: 24 additions & 2 deletions test/components/input/input_spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {componentSanityCheck} from "../../util";
import {componentSanityCheck, promiseWait} from "../../util";
import {
TestComponentBuilder,
beforeEach,
Expand All @@ -9,7 +9,7 @@ import {
injectAsync,
ComponentFixture
} from "angular2/testing";
import {Component, View, DebugElement} from "angular2/core";
import {Component, View, DebugElement, Input} from "angular2/core";
import {MdInput, MdInputContainer} from "../../../ng2-material/components/input/input";
import {By} from "angular2/platform/browser";

Expand All @@ -32,6 +32,8 @@ export function main() {
template: template
})
class TestComponent {

@Input() boundValue;
}

describe('Input', () => {
Expand Down Expand Up @@ -66,6 +68,26 @@ export function main() {
expect(api.input.value).toBe('');
});
}));
it('should emit change event when value binding is updated after init', injectAsync([], () => {
let tpl = `
<md-input-container>
<input md-input type="text" [value]="boundValue">
</md-input-container>`;
return setup(tpl).then((api: IInputFixture) => {
let newValue = 'something-great';
expect(api.input.value).toBe('');
return promiseWait().then(() => {
return new Promise((resolve) => {
api.input.mdChange.subscribe((changed: string) => {
expect(changed).toBe(newValue);
resolve();
});
api.fixture.componentInstance.boundValue = newValue;
api.fixture.detectChanges();
});
});
});
}));
});
});

Expand Down

0 comments on commit 0014bc4

Please sign in to comment.