Browse Source

Unsubscription.

pull/65/merge
Sebastian Stehle 9 years ago
parent
commit
a576a1f083
  1. 20
      src/Squidex/app/features/content/pages/contents/contents-page.component.ts
  2. 48
      src/Squidex/app/framework/angular/date-time-editor.component.ts

20
src/Squidex/app/features/content/pages/contents/contents-page.component.ts

@ -177,16 +177,16 @@ export class ContentsPageComponent extends AppComponentBase implements OnDestroy
public load(showInfo = false) {
this.appNameOnce()
.switchMap(app => this.contentsService.getContents(app, this.schema.name, this.contentsPager.pageSize, this.contentsPager.skip, this.contentsQuery))
.subscribe(dtos => {
this.contentItems = ImmutableArray.of(dtos.items);
this.contentsPager = this.contentsPager.setCount(dtos.total);
if (showInfo) {
this.notifyInfo('Contents reloaded.');
}
}, error => {
this.notifyError(error);
});
.subscribe(dtos => {
this.contentItems = ImmutableArray.of(dtos.items);
this.contentsPager = this.contentsPager.setCount(dtos.total);
if (showInfo) {
this.notifyInfo('Contents reloaded.');
}
}, error => {
this.notifyError(error);
});
}
public dropData(content: ContentDto) {

48
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,26 +57,33 @@ export class DateTimeEditorComponent implements ControlValueAccessor, OnInit, Af
public isDisabled = false;
public ngOnInit() {
this.timeControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.timeValue = null;
} else {
this.timeValue = moment(value, 'HH:mm:ss');
}
public ngOnDestroy() {
this.dateSubscription.unsubscribe();
this.timeSubscription.unsubscribe();
}
this.updateValue();
});
public ngOnInit() {
this.timeSubscription =
this.timeControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.timeValue = null;
} else {
this.timeValue = moment(value, 'HH:mm:ss');
}
this.dateControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.dateValue = null;
} else {
this.dateValue = moment(value, 'YYYY-MM-DD');
}
this.updateValue();
});
this.dateSubscription =
this.dateControl.valueChanges.subscribe(value => {
if (!value || value.length === 0) {
this.dateValue = null;
} else {
this.dateValue = moment(value, 'YYYY-MM-DD');
}
this.updateValue();
});
this.updateValue();
});
}
public writeValue(value: any) {

Loading…
Cancel
Save