Skip to content

Instantly share code, notes, and snippets.

@IntegerMan
Created February 13, 2020 04:27
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/bdd1c7b37219a092e5f6d15e0c600ccb to your computer and use it in GitHub Desktop.
Save IntegerMan/bdd1c7b37219a092e5f6d15e0c600ccb to your computer and use it in GitHub Desktop.
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