Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Preston Lamb pjlamb12

🏠
Working from home
View GitHub Profile
@pjlamb12
pjlamb12 / google-analytics.service.ts
Created Aug 21, 2020
Example Google Analytics service for Angular apps
View google-analytics.service.ts
import { Injectable, Renderer2, Inject, RendererFactory2 } from '@angular/core';
import { DOCUMENT } from '@angular/common';
import { RuntimeConfigLoaderService } from 'runtime-config-loader';
import { Router, RouterEvent, NavigationEnd } from '@angular/router';
import { filter, tap } from 'rxjs/operators';
declare let gtag: Function;
@Injectable({
providedIn: 'root',
@pjlamb12
pjlamb12 / book-list.js
Created Aug 29, 2019
Book/Rating List for Blake
View book-list.js
const bookList = [['Book 1', 'some Author'], ['Book 2', 'some Author'], ['Book 3', 'some Author']];
const ratingList = [[0, 3, 5], [3, 0, 5]];
const nameList = ['Preston', 'Blake'];
function getRatings() {
let personIndex = 0;
const returnObj = {};
while (personIndex < nameList.length) {
@pjlamb12
pjlamb12 / compodoc.js
Last active Sep 14, 2020
Generate Compodoc Documentation for each App and Library in an Nx workspace from a script
View compodoc.js
const angularJson = require('./angular.json');
const exec = require('child_process').exec;
const fs = require('fs');
const mainProjects = Object.keys(angularJson.projects).filter(proj => !proj.includes('e2e'));
const tsConfigPaths = parseTsconfigPaths();
function parseTsconfigPaths() {
const pathsArray = [];
for (const projectName of mainProjects) {
View article.md

The next Angular item we’ll test is a component. This is going to be very similar to the directive we just tested. But, even though it’ll look almost the exact same, I think it’ll be worth going through the exercise of testing the component.

This component’s purpose is to display a list of alerts that we want to show to our users. There is a related service that adds and removes the alerts and passes them along using a Subject. It is slightly complicated because we’re going to use a TemplateRef to pass in the template that the ngFor loop should use for the alerts. That way the implementing application can determine what the alerts should look like. Here’s the component:

@Component({
	selector: 'alerts-display',
	template: '<ng-template ngFor let-alert [ngForOf]="alerts$ | async" [ngForTemplate]="alertTemplate"></ng-template>',
	styleUrls: ['./alerts-display.component.scss'],
})
@pjlamb12
pjlamb12 / buildCE.sh
Created Mar 5, 2019
Angular Elements Build script
View buildCE.sh
ng build --prod --output-hashing=none && cat dist/ng-elements/runtime.js dist/ng-elements/polyfills.js dist/ng-elements/scripts.js dist/ng-elements/main.js > ../demo/ngelements.js
@pjlamb12
pjlamb12 / angular-community-involvement.md
Last active Aug 5, 2020
A list of ways I've tried to be involved in the Angular community
View angular-community-involvement.md

Community Involvement — Preston Lamb

People Impacted: 51,428

1. Summary

  • Thinkster.io Courses: 3
  • ngWeber Events: 5
    • Total Downloads/Views: 720+
  • Blog Posts: 27
View keybase.md

Keybase proof

I hereby claim:

  • I am pjlamb12 on github.
  • I am pjlamb12 (https://keybase.io/pjlamb12) on keybase.
  • I have a public key ASDSwRAtv2HhIo1JyOuZe-QXS4G-9dxyH0bhwZANe0vhYwo

To claim this, I am signing this object:

@pjlamb12
pjlamb12 / child.component.ts
Last active Jul 18, 2016
The child component's output event is called if you call the component's onTestOutputButtonClick() function directly, but if you try and emit an event from inside the service's callback, no event is emitted.
View child.component.ts
//Component Declaration
export class ChildComponent {
@Output() onOutputEvt: EventEmitter<any> = new EventEmitter<any>();
onTestOutputButtonClick() {
this.onOutputEvt.emit({data: 'Emitted data'});
}
makeAnUpdate(form) {
this._service.makeDbCall(data).subscribe(result => {
@pjlamb12
pjlamb12 / model.js
Created May 20, 2016
Sails.js Waterline Update Example
View model.js
function update(args, done) {
Model.update([{id: args.id}, {id2: args.id2}], [{field1: args.field1}, {field2: args.field2}]).exec(function(err, updatedModel) {
console.log('error on update: ', err);
console.log('updated model: ', updatedModel);
return updatedModel;
});
}
@pjlamb12
pjlamb12 / session.ts
Created Apr 26, 2016
NgZone After Auth0 Login
View session.ts
import {Injectable, NgZone} from 'angular2/core';
import {Http, Response, Headers} from 'angular2/http';
import {Router} from 'angular2/router';
import {tokenNotExpired} from 'angular2-jwt';
import 'rxjs/add/operator/map';
import {AppConfig} from '../services/config';
declare var Auth0Lock: any;
You can’t perform that action at this time.