Skip to content

Instantly share code, notes, and snippets.

@anmolio
anmolio / componentTwo.component.ts
Last active May 10, 2020 10:57
ComponentTwo : Unrelated Components subscribing to data using a serivce (BehaviorSubject)
import { Component, OnInit } from '@angular/core';
import { StatusService } from "../status.service";
@Component({
selector: 'app-componenttwo',
template: `
The status id - {{status}}
<button (click)="changeStatus()">Change Message</button>
`,
styleUrls: ['./sibling.component.css']
@anmolio
anmolio / componentOne.component.ts
Last active April 6, 2020 07:25
ComponentOne : Unrelated Components subscribing to data using a serivce (BehaviorSubject)
import { Component, OnInit } from '@angular/core';
import { StatusService } from "../status.service";
@Component({
selector: 'app-componentone',
template: `
The status is - {{status}}
`,
styleUrls: ['./sibling.component.css']
})
@anmolio
anmolio / status.service.ts
Last active May 10, 2020 10:57
Example of an angular service using RxJs BehaviorSubject for data sharing.
import { Injectable } from '@angular/core';
import { BehaviorSubject } from 'rxjs';
@Injectable()
export class StatusService {
private statusSource = new BehaviorSubject('OFF'); // set default status
currentStatus = this.statusSource.asObservable();
constructor() { }
@anmolio
anmolio / base64_to_image.php
Last active March 9, 2020 18:48
PHP code to convert base 64 string to an image.
<?php
$base64String = "R0lGODdhAQABAPAAAP8AAAAAACwAAAAAAQABAAACAkQBADs";
$image = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '',$base64String));
$FILE = time().rand(111111111, 999999999) . '.png';
?>
@anmolio
anmolio / scripts.js
Last active April 6, 2020 07:18
A custom script.js file inside assets folder - Angular 9 to create global functions in project.
/* You can add global JS/TS functions to this file
Examples:
1. validateUrl(url)
2. rediret(url)
3. objectLength(object) { return Objects.keys(object).length; }
*/
$(function() {
// Load webflow after jquery to resolve conflicts and transitions
$.getScript('assets/js/webflow.js');
@anmolio
anmolio / angular.json
Last active December 22, 2019 07:33
Sample angluar.json file with third patry JS in scripts
...
...
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "tsconfig.app.json",
"aot": false,
"scripts": [
"src/assets/js/jquery-3.4.1.min.js",
"src/assets/js/webflow.js",
"src/assets/js/script.js"