Created
February 13, 2020 04:27
-
-
Save IntegerMan/bdd1c7b37219a092e5f6d15e0c600ccb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {LiveAnnouncer} from '@angular/cdk/a11y'; | |
import {Component, Input, OnDestroy, OnInit} from '@angular/core'; | |
import {Subscription} from 'rxjs'; | |
import {StoryEntry} from '../../Model/StoryEntry'; | |
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, | |
private liveAnnouncer: LiveAnnouncer) { | |
// Hiding initialization of Entries collection | |
} | |
ngOnInit() { | |
this.entrySub = this.storyService.EntryAdded.subscribe(entry => this.onEntryAdded(entry)); | |
} | |
ngOnDestroy() { | |
if (this.entrySub) { | |
this.entrySub.unsubscribe(); | |
this.entrySub = null; | |
} | |
} | |
private onEntryAdded(entry: StoryEntry) { | |
this.Entries.push(entry); | |
this.liveAnnouncer.announce(entry.Text); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment