Skip to content

Instantly share code, notes, and snippets.

View AhsanAyaz's full-sized avatar

Muhammad Ahsan Ayaz AhsanAyaz

View GitHub Profile
@AhsanAyaz
AhsanAyaz / watch-service.ts
Created February 25, 2018 09:40
Watch Service used with the Stop Watch Box Component I built using Stencil
export class WatchService {
/**
* @author Ahsan Ayaz
* @desc Calculates the units and sets in string format.
* @param unit value of the unit in numbers
* @return {string} the string representation of the unit's value with at least 2 digits
*/
getTimeString(unit: number): string {
return (unit ? (unit > 9 ? unit : "0" + unit) : "00").toString();
}
@AhsanAyaz
AhsanAyaz / app.component.ts
Last active April 9, 2018 10:49
AppComponent before implementing ListKeyManager
import { Component, OnInit } from "@angular/core";
import { UsersService } from "./core/services/users.service";
import { first } from "rxjs/operators";
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
})
export class AppComponent implements OnInit {
@AhsanAyaz
AhsanAyaz / app.component.html
Last active April 9, 2018 19:13
AppComponent's view for NgKeyListDemo app
<div class="users-page">
<div class="users-page__loading" *ngIf="isLoadingUsers">
Loading Users
</div>
<div class="users-age__main" *ngIf="!isLoadingUsers">
<h3 class="users-page__main__heading">
Users List
</h3>
<div class="users-page__main__search">
<input type="text" [(ngModel)]="searchQuery" placeholder="search users by name" (keyup)="handleKeyUp($event)">
@AhsanAyaz
AhsanAyaz / list-item.component.html
Created April 9, 2018 10:52
ListItemComponent for NgKeyListDemo app
<div class="item" [class.item--active]="isActive">
<div class="item__img">
<img [src]="item.picture.thumbnail">
</div>
<div class="item__content">
<div class="item__content__name">{{item.name.first}} {{item.name.last}}</div>
<div class="item__content__email">{{item.email}}</div>
</div>
</div>
@AhsanAyaz
AhsanAyaz / app.component.ts
Created April 9, 2018 10:55
AppComponent after adding QueryList code for getting list items
import { Component, OnInit, QueryList, ViewChildren } from "@angular/core";
import { UsersService } from "./core/services/users.service";
import { first } from "rxjs/operators";
import { ListKeyManager } from "@angular/cdk/a11y";
import { ListItemComponent } from "./core/components/list-item/list-item.component"; // importing so we can use with `@ViewChildren and QueryList
@Component({
selector: "app-root",
templateUrl: "./app.component.html",
styleUrls: ["./app.component.scss"]
@AhsanAyaz
AhsanAyaz / app.component.ts
Last active April 9, 2018 19:13
AppComponent after adding (keyup) handler on the search input
...
import { ListKeyManager } from '@angular/cdk/a11y';
import { ListItemComponent } from './core/components/list-item/list-item.component';
import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes';
...
export class AppComponent implements OnInit {
...
keyboardEventsManager: ListKeyManager<any>;
searchQuery: string;
@AhsanAyaz
AhsanAyaz / app.component.ts
Last active October 27, 2023 14:20
AppComponent after initializing the KeyboardEventsManager change event
import { Component, OnInit, QueryList, ViewChildren } from '@angular/core';
import { UsersService } from './core/services/users.service';
import { first } from 'rxjs/operators';
import { ListKeyManager } from '@angular/cdk/a11y';
import { ListItemComponent } from './core/components/list-item/list-item.component';
import { UP_ARROW, DOWN_ARROW, ENTER } from '@angular/cdk/keycodes';
@Component({
selector: 'app-root',
@AhsanAyaz
AhsanAyaz / list-item.component.ts
Created April 9, 2018 11:30
ListItemComponent for NgKeyListDemo app
import { Component, OnInit, Input, EventEmitter, Output } from '@angular/core';
@Component({
selector: 'app-list-item',
templateUrl: './list-item.component.html',
styleUrls: ['./list-item.component.scss']
})
export class ListItemComponent implements OnInit {
@Input() item;
@Output() itemSelected = new EventEmitter<any>();
@AhsanAyaz
AhsanAyaz / logger.ts
Last active May 22, 2019 18:36
Custom logging service for Angular
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
export interface LoggerConfig {
prefix?: string;
color?: string;
enabled: boolean;
}
@Injectable({
@AhsanAyaz
AhsanAyaz / du-interfaces_initial.ts
Created September 6, 2019 07:05
Discriminated Unions in Typescript
enum CarTransmission {
Automatic = 200,
Manual = 300
}
interface IMotorcycle {
vType: "motorcycle"; // discriminant
make: number; // year
}