All files / src/app/pages/search search.component.ts

100% Statements 20/20
100% Branches 0/0
100% Functions 2/2
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 571x 1x 1x                   1x                         1x 1x 1x 1x             1x           1x     1x   1x 1x 1x 1x 1x 1x 1x        
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
import { AlertService, PageService } from '../../services';
 
/**
 * Search Component
 */
@Component({
    selector: 'app-search',
    templateUrl: './search.component.html',
    styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit {
    /** safe html of google custom search API box */
    gcseSearchBox: SafeHtml;
    /** safe html of google custom search API result */
    gcseSearchResult: SafeHtml;
 
    /**
     * constructor of SearchComponent
     * @param platformId: PLATFORM_ID
     * @param pageService: PageService
     * @param alert: AlertService
     * @param sanitizer: DomSanitizer
     */
    constructor(@Inject(PLATFORM_ID) private readonly platformId: string,
                public pageService: PageService,
                public alert: AlertService,
                private readonly sanitizer: DomSanitizer) {
    }
 
    /**
     * ngOnInit
     */
    ngOnInit(): void {
        this.pageService.initPage({
            title: 'Search Result',
            description: 'Search Result'
            // seo: {names: {robots: 'noindex, nofollow'}}
        });
 
        this.gcseSearchBox = this.sanitizer.bypassSecurityTrustHtml(
            '<gcse:searchbox-only resultsUrl="/search"></gcse:searchbox-only>'
        );
        this.gcseSearchResult = this.sanitizer.bypassSecurityTrustHtml('<gcse:searchresults-only></gcse:searchresults-only>');
 
        const cx = '009513577206836808676:joyznri9mmm';
        const gcse = document.createElement('script');
        gcse.type = 'text/javascript';
        gcse.async = true;
        gcse.src = `https://cse.google.com/cse.js?cx=${cx}`;
        const s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(gcse, s);
    }
 
}