Skip to content

Instantly share code, notes, and snippets.

View rajaramtt's full-sized avatar
🤘
Learning and Sharing

Raja Ram T rajaramtt

🤘
Learning and Sharing
  • Hyderabad, India
View GitHub Profile
@rajaramtt
rajaramtt / cors.js
Created October 31, 2018 13:31
CORS headers in node, php
app.use(function (req, res, next) {
res.setHeader('Access-Control-Allow-Origin', 'http://localhost:4200');
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, PATCH, DELETE');
res.setHeader('Access-Control-Allow-Headers', 'X-Requested-With,content-type');
res.setHeader('Access-Control-Allow-Credentials', true);
next();
@rajaramtt
rajaramtt / map-example-in-angular7.ts
Created December 17, 2018 13:58
Observable map key example
import { Observable, BehaviorSubject, ReplaySubject, pipe } from 'rxjs';
import { of as observableOf } from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { distinctUntilChanged } from 'rxjs/operators';
return this.http.post(`${environment.host}${environment.loginService}`, credentials)
.pipe(
map(response => {
const storage = sessionStorage;
@rajaramtt
rajaramtt / local-references.ts
Last active February 18, 2019 17:44
Local References and ViewChild decarator in Angular
// <input type="text" class="form-control" trim #giftName />
import { Component, OnInit, ViewChild, ElementRef } from '@angular/core';
export class UserComponent implements OnInit {
userNickName: String = '';
..
@rajaramtt
rajaramtt / Content Projection.html
Last active February 18, 2019 17:49
Content Projection
<ng-content select="router-outlet"></ng-content>
<router-outlet></router-outlet>
@rajaramtt
rajaramtt / AngularLifecycle.txt
Last active February 18, 2019 17:58
Angular Life cycle
ngOnChanges Called after a bound input property changes
ngOnInit Called once the component is initialized
ngDoCheck Called during every change detection run
ngAfterContentInit Called after content (ng-content) has been projected into view
ngAfterContentChecked Called every time the projected content has been checked
ngAfterViewInit Called after the component’s view (and child views) has been initialized
ngAfterViewChecked Called every time the view (and child views) have been checked
ngOnDestroy Called once the component is about to be destroyed
<!-- attention, we have the c_highlight class -->
<!-- c_highlight is the selector property value of the directive -->
<p class="c_highlight">
Some text.
</p>
@rajaramtt
rajaramtt / Renderer-vs-ElementRef.text
Last active February 18, 2019 18:18
Difference between Renderer and ElementRef in angular 2 / ElementRef vs. ViewContainerRef vs. TemplateRef
The Renderer is a class that is a partial abstraction over the DOM. Using the Renderer for manipulating the DOM doesn't break server-side rendering or Web Workers (where direct access to the DOM would break).
ElementRef is a class that can hold a reference to a DOM element. This is again an abstraction to not break in environments where the browsers DOM isn't actually available.
If ElementRef is injected to a component, the injected instance is a reference to the host element of the current component.
There are other ways to acquire an ElementRef instance like @ViewChild(), @ViewChildren(), @ContentChild(), @ContentChildren(). In this case ElementRef is a reference to the matching element(s) in the template or children.
Renderer and ElementRef are not "either this or that", but instead they have to be used together to get full platform abstraction.
@rajaramtt
rajaramtt / hn.resolver.ts
Last active February 19, 2019 18:44
Route Resolvers in Angular 7
import { Injectable } from '@angular/core';
import { HnService } from './hn.service';
import { Resolve } from '@angular/router';
import { ActivatedRouteSnapshot } from '@angular/router';
@Injectable()
export class HnResolver implements Resolve<any> {
constructor(private hnService: HnService) {}
@rajaramtt
rajaramtt / nginx
Created November 27, 2018 12:37
nginx angular and node proxy config
server {
listen 80;
server_name 0.0.0.0;
root /var/www/html/dist;
index index.html index.htm;
@rajaramtt
rajaramtt / Observable, Subject, BehaviorSubject, ReplaySubject and AsyncSubject .txt
Last active March 31, 2019 20:08
Observable, Subject, BehaviorSubject, ReplaySubject and AsyncSubject
Observable: Subscribe to it to get the values
Subject: Same but you also have control of the values that you want to emit into it (can subscribe to it but also emit)
ReplaySubject:
Same as subject but will keep track of the N latest emitted values and every time you subscribe to it,
it'll emit those N values
BehaviorSubject:
Subject where you have to set a default value,
if you subscribe to it before anything has been emitted you'll get the default value