Browse Source

Unsubscription.

pull/65/merge
Sebastian Stehle 9 years ago
parent
commit
a576a1f083
  1. 14
      src/Squidex/app/framework/angular/date-time-editor.component.ts

14
src/Squidex/app/framework/angular/date-time-editor.component.ts

@ -5,8 +5,9 @@
* Copyright (c) Sebastian Stehle. All rights reserved
*/
import { AfterViewInit, Component, forwardRef, ElementRef, Input, OnInit, ViewChild } from '@angular/core';
import { AfterViewInit, Component, forwardRef, ElementRef, Input, OnInit, OnDestroy, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormControl, NG_VALUE_ACCESSOR } from '@angular/forms';
import { Subscription } from 'rxjs';
import * as moment from 'moment';
let Pikaday = require('pikaday/pikaday');
@ -23,7 +24,9 @@ export const SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR: any = {
templateUrl: './date-time-editor.component.html',
providers: [SQX_DATE_TIME_EDITOR_CONTROL_VALUE_ACCESSOR]
})
export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, AfterViewInit {
export class DateTimeEditorComponent implements ControlValueAccessor, OnDestroy, OnInit, AfterViewInit {
private timeSubscription: Subscription;
private dateSubscription: Subscription;
private picker: any;
private timeValue: any | null = null;
private dateValue: any | null = null;
@ -54,7 +57,13 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
public isDisabled = false;
public ngOnDestroy() {
this.dateSubscription.unsubscribe();
this.timeSubscription.unsubscribe();
}
public ngOnInit() {
this.timeSubscription =
this.timeControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.timeValue = null;
@ -65,6 +74,7 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
this.updateValue();
});
this.dateSubscription =
this.dateControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.dateValue = null;

Loading…
Cancel
Save