Skip to content

Instantly share code, notes, and snippets.

@elvinmeza
elvinmeza / angular.json
Last active July 27, 2018 22:27
Loading JQuery on Angular
"scripts": [
"node_modules/jquery/dist/jquery.min.js"
]
@elvinmeza
elvinmeza / .npmignore
Last active May 7, 2018 06:37
Publishing a simple Typescript library into npm
src
@elvinmeza
elvinmeza / 01.ts
Created November 24, 2017 20:56
Angular Reactive forms with Custom Validators
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpClientInMemoryWebApiModule } from 'angular-in-memory-web-api';
import { AppComponent } from './app.component';
import { InMemoryDataService } from './services/in-memory-data.service';
import { AuthInterceptor } from './shared/auth-interceptor';
import { RockBand } from './services/rock-bands.service';
import { Component, OnInit } from '@angular/core';
import { RockBand } from './services/rock-bands.service';
@Component({
selector: 'app-root',
template: `
<h2>List of Rock Bands that rocks!: </h2>
<ul>
<li *ngFor="let rockBand of rockBands">
{{rockBand.id}} - {{rockBand.name}}
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
import { Injectable } from '@angular/core';
@Injectable()
export class RockBand {
private rockBandsUrl = 'api/rockBands';
constructor(private http: HttpClient) {
}
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const rockBands = [
{ id: 1, name: 'The Beatles' },
{ id: 2, name: 'Led Zeppelin' },
{ id: 3, name: 'Pink Floyd' },
{ id: 4, name: 'The Rolling Stones' },
{ id: 5, name: 'Queen' },
@elvinmeza
elvinmeza / auth-interceptor.ts
Created November 21, 2017 15:50
Angular Http Interceptor
import {Injectable} from '@angular/core';
import {HttpEvent, HttpInterceptor, HttpHandler, HttpRequest} from '@angular/common/http';
import { Observable } from 'rxjs/Observable';
@Injectable()
export class AuthInterceptor implements HttpInterceptor {
// constructor( INJECT YOUR AUTH SERVICE HERE )
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {