Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Last active February 9, 2020 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IntegerMan/384d197b0ad0236e2c45a79517e9e8d5 to your computer and use it in GitHub Desktop.
Save IntegerMan/384d197b0ad0236e2c45a79517e9e8d5 to your computer and use it in GitHub Desktop.
import {Component, Input, OnDestroy, OnInit} from '@angular/core';
import {Subscription} from 'rxjs';
import {StoryEntry} from '../../Model/StoryEntry';
import {StoryEntryType} from '../../Model/StoryEntryType';
import {StoryService} from '../story.service';
@Component({
selector: 'app-story-view',
templateUrl: './story-view.component.html',
styleUrls: ['./story-view.component.scss']
})
export class StoryViewComponent implements OnInit, OnDestroy {
@Input()
public Entries: StoryEntry[] = [];
private entrySub: Subscription;
constructor(private storyService: StoryService) {
// Initial entries to the Entries collection are set here, but omitted for this sample
}
ngOnInit() {
this.entrySub = this.storyService.EntryAdded.subscribe(entry => this.Entries.push(entry));
}
ngOnDestroy() {
if (this.entrySub) {
this.entrySub.unsubscribe();
this.entrySub = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment