File

src/lib/logging-viewer-search/logging-viewer-search.component.ts

Description

Component for displaying the search bar for filtering the current logs.

The component can be embedded in any web page using:

<ionic-logging-viewer-search placeholder="Search"></ionic-logging-viewer-search>

Implements

OnInit OnDestroy

Metadata

selector ionic-logging-viewer-search
styleUrls ./logging-viewer-search.component.scss
templateUrl ./logging-viewer-search.component.html

Index

Properties
Methods
Inputs

Constructor

constructor(loggingService: LoggingService, loggingViewerFilterService: LoggingViewerFilterService)

Creates a new instance of the component.

Parameters :
Name Type Optional
loggingService LoggingService No
loggingViewerFilterService LoggingViewerFilterService No

Inputs

placeholder
Type : string

Placeholder to be shown in the empty search bar.

Methods

Public ngOnDestroy
ngOnDestroy()

Clean up.

Returns : void
Public ngOnInit
ngOnInit()

Initialize the component.

This is done by reading the filter data from LoggingViewerFilterService.

Returns : void
Public onSearchChanged
onSearchChanged()

Callback when the search value was changed in the UI.

Returns : void

Properties

Public search
Type : string

Current search value.

import { Component, OnInit, OnDestroy, Input } from "@angular/core";

import { Subscription } from "rxjs";

import { LoggingService, Logger } from "ionic-logging-service";

import { LoggingViewerFilterService } from "../logging-viewer-filter.service";

/**
 * Component for displaying the search bar for filtering the current logs.
 *
 * The component can be embedded in any web page using:
 *
 * &lt;ionic-logging-viewer-search placeholder="Search">&lt;/ionic-logging-viewer-search>
 */
@Component({
	selector: "ionic-logging-viewer-search",
	templateUrl: "./logging-viewer-search.component.html",
	styleUrls: ["./logging-viewer-search.component.scss"]
})
export class LoggingViewerSearchComponent implements OnInit, OnDestroy {

	/**
	 * Placeholder to be shown in the empty search bar.
	 */
	@Input()
	public placeholder: string;

	/**
	 * Current search value.
	 */
	public search: string;

	private logger: Logger;
	private filterChangedSubscription: Subscription;

	/**
	 * Creates a new instance of the component.
	 */
	constructor(
		loggingService: LoggingService,
		private loggingViewerFilterService: LoggingViewerFilterService) {

		this.logger = loggingService.getLogger("Ionic.Logging.Viewer.Search.Component");
		const methodName = "ctor";
		this.logger.entry(methodName);

		this.logger.exit(methodName);
	}

	/**
	 * Initialize the component.
	 *
	 * This is done by reading the filter data from [LoggingViewerFilterService](LoggingViewerFilterService.html).
	 */
	public ngOnInit(): void {
		const methodName = "ngOnInit";
		this.logger.entry(methodName);

		if (!this.placeholder) {
			this.placeholder = "Search";
		}
		this.search = this.loggingViewerFilterService.search;

		// subscribe to loggingViewerFilterService.filterChanged event, to refresh,
		// when someone else modifies the search value
		this.filterChangedSubscription = this.loggingViewerFilterService.filterChanged.subscribe(() => {
			this.search = this.loggingViewerFilterService.search;
		});

		this.logger.exit(methodName);
	}

	/**
	 * Clean up.
	 */
	public ngOnDestroy(): void {
		const methodName = "ngOnDestroy";
		this.logger.entry(methodName);

		this.filterChangedSubscription.unsubscribe();

		this.logger.exit(methodName);
	}

	/**
	 * Callback when the search value was changed in the UI.
	 */
	public onSearchChanged(): void {
		const methodName = "onSearchChanged";
		this.logger.entry(methodName, this.search);

		this.loggingViewerFilterService.search = this.search;

		this.logger.exit(methodName);
	}
}
<ion-searchbar placeholder="{{placeholder}}" [(ngModel)]="search" (ionChange)="onSearchChanged()"></ion-searchbar>

./logging-viewer-search.component.scss

Legend
Html element
Component
Html element with directive

result-matching ""

    No results matching ""