Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

angular 13 component example

import { 
    Component, 
    OnInit, 
    ElementRef, 
    ViewChild, 
    OnDestroy, 
    ChangeDetectionStrategy, 
    ChangeDetectorRef } from '@angular/core';

import { Router } from '@angular/router';
import { User } from 'src/app/common/auth/user';
import { AuthService } from 'src/app/common/services/auth.service';
import { MatSnackBar } from '@angular/material/snack-bar';
import { takeUntil } from 'rxjs/operators';

@Component({
  selector: 'app-header',
  templateUrl: './header.component.html',
  styleUrls: ['./header.component.scss'],
  changeDetection: ChangeDetectionStrategy.OnPush
})
export class HeaderComponent implements OnInit, OnDestroy {
  @ViewChild('searchBar') searchBar: ElementRef | null = null;
  public signedIn: boolean = false;
  public authUser: User | null = null;
  private destroyNotifier$: Subject<boolean> = new Subject<boolean>();
  constructor(
    public authService: AuthService,
    private router: Router, 
    private snackBar: MatSnackBar, 
    private changeDetectorRef: ChangeDetectorRef) { }

  ngOnInit(): void {
    this.authService.authState
    .pipe(takeUntil(this.destroyNotifier$))
    .subscribe({
      next: (authState: AuthState) => {
        this.signedIn = authState.signedIn;
        this.authUser = authState.currentUser;
        this.changeDetectorRef.markForCheck();
      }
    });
  }
  ngOnDestroy(): void {
    this.destroyNotifier$.next(true);
    this.destroyNotifier$.complete();
  }
  logOut(): void {
    this.authService.logOut();
    this.router.navigateByUrl('/users/login');
  }
  findUsers(): void {
    const searchText = this.searchBar?.nativeElement.value;
    if(searchText == ''){
      this.snackBar.open('Enter a search text', 'Ok', {
        duration: 5 * 1000
      });
      return;
    }
    const result = this.authService.findUsers(searchText);
    console.log(result);
  }
}
Comment

PREVIOUS NEXT
Code Example
Typescript :: react-router-dom for typescript 
Typescript :: howt o make sure its a valid sudoku in python 
Typescript :: typescript typecast 
Typescript :: typescript class interface 
Typescript :: google fonts icons size classes 
Typescript :: Add correct host key in /Users/ckaburu/.ssh/known_hosts to get rid of this message 
Typescript :: if exits python sql 
Typescript :: remove wordpress products all at once 
Typescript :: NullInjectorError: R3InjectorError(DynamicTestModule)[AdminTestCentersComponent - ToastrService - InjectionToken ToastConfig - InjectionToken ToastConfig]: NullInjectorError: No provider for InjectionToken ToastConfig! 
Typescript :: number of elements in list in python 
Typescript :: typescript slice string 
Typescript :: how to define an array type in typescript 
Typescript :: activate jquery in typescript 
Typescript :: typescript list concat 
Typescript :: NFS is reporting that your exports file is invalid. Vagrant does this check before making any changes to the file. Please correct the issues below and execute "vagrant reload": 
Typescript :: wordpress number of posts by user 
Typescript :: typescript generic record 
Typescript :: python convert long floats to usd 
Typescript :: search an array of objects with specific object property value 
Typescript :: get type of element of array typescript 
Typescript :: create npm module typescript 
Typescript :: concat type typescript 
Typescript :: how to read temp file in windowsnodejs 
Typescript :: subscribe form changes 
Typescript :: command line arguments in java 
Typescript :: two absolute elements are overlapping css help 
Typescript :: laravel no tests executed 
Typescript :: abstract data structure types 
Typescript :: convert interface optional in typescript 
Typescript :: this typescript 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =