Skip to content

Instantly share code, notes, and snippets.

Avatar
👋
_

Chris House crh225

👋
_
View GitHub Profile
@crh225
crh225 / delete.gist.ts
Last active Feb 17, 2020
delete.gist.ts
View delete.gist.ts
delete(id: string): void {
this._db
.collection<Jobs>('jobs')
.doc(id)
.delete()
.then(() => {
this.snackBar.open('Job was deleted successfully', 'Ok', {
duration: 2000,
});
});
View editfirestore.ts
editJob() {
this._db.collection<any>('jobs')
.doc(this.id)
.update(
{
company: this.jobForm.get('company').value,
description: this.jobForm.get('description').value,
title: this.jobForm.get('title').value
}
).then(() => {
@crh225
crh225 / updatefirestore.ts
Last active Feb 17, 2020
updatefirestore.ts
View updatefirestore.ts
ngOnInit() {
this.route.paramMap.subscribe((params: ParamMap) => {
this.id = params.get('id');
this._db
.collection<Jobs>('jobs')
.doc(
params.get('id')
).valueChanges()
.subscribe((item) => {
this.jobForm.patchValue(item);
@crh225
crh225 / readjobs.ts
Last active Feb 17, 2020
readjobs.ts
View readjobs.ts
constructor(public snackBar: MatSnackBar, public afAuth: AngularFireAuth, db: AngularFirestore) {
this.jobs = db
.collection<Jobs>('jobs')
.snapshotChanges()
.pipe(map(actions => {
return actions.map(a => {
const data = a.payload.doc.data();
const id = a.payload.doc.id;
return { id, ...data };
});
@crh225
crh225 / addjob.ts
Last active Feb 17, 2020
addjob.ts
View addjob.ts
addJob() {
this._db
.collection<Jobs>('jobs')
.add(
{
company: this.jobForm.get('company').value,
description: this.jobForm.get('description').value,
title: this.jobForm.get('title').value
}
).then(() => {
View jobform.ts
jobForm = new FormGroup({
company: new FormControl('', Validators.required),
description: new FormControl('', Validators.required),
title: new FormControl('', Validators.required),
salary: new FormControl('')
});
@crh225
crh225 / angularfire-form.ts
Created Feb 17, 2020
angularfire-form.ts
View angularfire-form.ts
<form class="job-form" [formGroup]="jobForm">
<mat-form-field class="full-width">
<mat-label>Company</mat-label>
<input matInput placeholder="Ex. Google" formControlName="company" required>
<mat-error *ngIf="!jobForm.get('company').valid">Required</mat-error>
</mat-form-field>
<mat-form-field class="full-width">
<mat-label>Job Title</mat-label>
<input matInput placeholder="Ex. Sr. Software Engineer" formControlName="title" required>
<mat-error *ngIf="!jobForm.get('title').valid">Required</mat-error>
@crh225
crh225 / angularfire-constructor.ts
Created Feb 17, 2020
angularfire-constructor.ts
View angularfire-constructor.ts
constructor(db: AngularFirestore) {
this._db = db;
}
View bg-color.pipe
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'bgColorPipe'
})
export class BgColorPipePipe implements PipeTransform {
transform(value: any, args?: any): any {
if(value === 'red'){
console.log('hit');
View component.html
<hello name="{{ name }}"></hello>
<p [ngStyle]="{'background-color': getColor()}">
Start editing to see some magic happen :)
</p>
<table>
<tr [ngStyle]="{'background-color': getColor()}">
<th [ngStyle]="{'background-color': getColor()}">Company</th>
<th [ngStyle]="{'background-color': getColor()}">Contact</th>
<th [ngStyle]="{'background-color': getColor()}">Country</th>