]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/share/title/title.component.ts
LP1813647 Angular page title component & sandbox example
[Evergreen.git] / Open-ILS / src / eg2 / src / app / share / title / title.component.ts
1 import {Component, Input, AfterViewInit, ViewChild} from '@angular/core';
2 import {Title} from '@angular/platform-browser';
3 import {StringComponent} from '@eg/share/string/string.component';
4
5 /*
6     <eg-title i18n-prefix i18n-suffix
7         prefix="Patron #{{patronId}}
8         suffix="Staff Client">
9     </eg-title>
10
11     Tab title shows (in en-US):  "Patron #123 - Staff Client"
12 */
13
14 @Component({
15   selector: 'eg-title',
16   templateUrl: 'title.component.html'
17 })
18
19 export class TitleComponent implements AfterViewInit {
20
21     initDone: boolean;
22
23     pfx: string;
24     @Input() set prefix(p: string) {
25         this.pfx = p;
26         this.setTitle();
27     }
28
29     sfx: string;
30     @Input() set suffix(s: string) {
31         this.sfx = s;
32         this.setTitle();
33     }
34
35     @ViewChild('titleString') titleString: StringComponent;
36
37     constructor(private title: Title) {}
38
39     ngAfterViewInit() {
40         this.initDone = true;
41         this.setTitle();
42     }
43
44     setTitle() {
45
46         // Avoid setting the title while the page is still loading
47         if (!this.initDone) { return; }
48
49         setTimeout(() => {
50             this.titleString.current({pfx: this.pfx, sfx: this.sfx})
51             .then(txt => this.title.setTitle(txt));
52         });
53     }
54 }
55