diff --git a/modules/angular2/src/change_detection/pipes/promise_pipe.ts b/modules/angular2/src/change_detection/pipes/promise_pipe.ts index 159426386d..7fb0bbec25 100644 --- a/modules/angular2/src/change_detection/pipes/promise_pipe.ts +++ b/modules/angular2/src/change_detection/pipes/promise_pipe.ts @@ -44,7 +44,11 @@ export class PromisePipe extends Pipe { supports(promise): boolean { return PromiseWrapper.isPromise(promise); } onDestroy(): void { - // NO-OP + if (isPresent(this._sourcePromise)) { + this._latestValue = null; + this._latestReturnedValue = null; + this._sourcePromise = null; + } } transform(promise: Promise): any { diff --git a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js index 5119f19c5d..9099b0fea4 100644 --- a/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js +++ b/modules/angular2/test/change_detection/pipes/promise_pipe_spec.js @@ -84,6 +84,26 @@ export function main() { async.done(); }, 0) })); + + describe("onDestroy", () => { + it("should do nothing when no source", () => { + expect(() => pipe.onDestroy()).not.toThrow(); + }); + + it("should dispose of the existing source", inject([AsyncTestCompleter], (async) => { + pipe.transform(completer.promise); + expect(pipe.transform(completer.promise)).toBe(null); + completer.resolve(message) + + + TimerWrapper.setTimeout(() => { + expect(pipe.transform(completer.promise)).toEqual(new WrappedValue(message)); + pipe.onDestroy(); + expect(pipe.transform(completer.promise)).toBe(null); + async.done(); + }, 0); + })); + }); }); }); }