Skip to content

Instantly share code, notes, and snippets.

View Bilkiss's full-sized avatar

Bilkiss Dulloo Bilkiss

  • TechSphere Labs
  • Mauritius
View GitHub Profile
import { Injectable } from '@angular/core';
import { BehaviorSubject, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class StorageService {
private storeDataSubjects: Map<string, BehaviorSubject<any>> = new Map();
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class StorageService {
constructor() { }
<button (click)=”deleteItem()”>Delete item</button>
// we are now also importing SweetAlertOptions in our decorator
import Swal, {SweetAlertOptions} from 'sweetalert2';
// Confirmable is now a factory function, with an optional parameter object
export function Confirmable(options?: SweetAlertOptions) {
// our factory function will return our actual decorator function, but now we have
// an actual options object to configure our alert box :)
return (target: Object, propertyKey: string, descriptor: PropertyDescriptor) => {
// the usual, caching the original implementation
import { Component, OnInit } from '@angular/core';
import Swal from 'sweetalert2';
@Component({
selector: 'example-component',
template: ‘Swal component!'
})
export class ExampleComponent implements OnInit {
constructor() {}
import { Component } from '@angular/core';
import { MyService } from './my-service';
@Component({
selector: 'example-component',
template: 'More component example!'
})
export class ExampleComponent {
constructor(myService: MyService) {
console.log(myService); // MyService
import { Component, HostListener } from '@angular/core';
@Component({
selector: 'example-component',
template: ‘Hey another component!'
})
export class ExampleComponent {
@HostListener('click', ['$event'])
onHostClick(event: Event) {
// clicked, `event` available
<example-component
[exampleProperty]="exampleData">
</example-component>
import { NgModule } from '@angular/core';
@NgModule({
imports: [],
declarations: [],
})
export class ExampleModule {
constructor() {
console.log('Hi, I am an example module!');
}
import { Component } from '@angular/core';
@Component({
selector: 'example-component',
template: '<div>Hello world! I'm an example component!</div>',
})
export class ExampleComponent {
constructor() {
console.log('Hey I am an example component!');