This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: https://stackblitz.com/edit/angular-config-callback | |
import {Component, OnInit} from '@angular/core'; | |
@Component({ | |
selector: 'app-projects-something', | |
templateUrl: 'app-projects-something.html', | |
styleUrls: ['app-projects-something.scss'] | |
}) | |
export class SomethingSomethingComponent implements OnInit { | |
config: object; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {NgModule} from '@angular/core'; | |
import {RouterModule, Routes} from '@angular/router'; | |
import {DashboardViewRouteComponent} from '@routes/dashboard-view-route/dashboard-view-route.component'; | |
import {ProjectsViewRouteComponent} from '@routes/projects-view-route/projects-view-route.component'; | |
import {ProjectsViewDetailsRouteComponent} from '@routes/projects-view-details-route/projects-view-details-route.component'; | |
import {ProjectsAddViewRouteComponent} from '@routes/projects-add-view-route/projects-add-view-route.component'; | |
import {ProjectsViewDetailsTableComponent} from '@routes/projects-view-details-table/projects-view-details-table.component'; | |
const routes: Routes = [ | |
{path: '', redirectTo: 'dashboard', pathMatch: 'full'}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Completey omit the 'ContentType: multipart/form-data' headers | |
// const httpUploadOptions = { | |
// headers: new HttpHeaders({ | |
// 'Content-Type': 'multipart/form-data' | |
// }) | |
// }; | |
const str = JSON.stringify('your Blob or Array'); | |
const fd = new FormData(); | |
const file = new File([str], 'fileName'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// angular.identity: see https://softwareengineering.stackexchange.com/a/283119 | |
// Content-Type: undefined: see https://www.uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs/ | |
// new File([data], file): must be a blob or array see https://developer.mozilla.org/en-US/docs/Web/API/Blob | |
var fd = new FormData(), | |
file = new File([data], objectName); | |
fd.append('file', file); | |
return $http.put('path/to/url', fd, { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findIndex | |
arr.findIndex((el) => { | |
return el.val === another.val; | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
arr.map(function (o) {return attr;}).indexOf(key) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
this.http.get('https://jsonplaceholder.typicode.com/users') | |
.subscribe((users) => { | |
this.users = users; | |
}, (err) => { | |
console.log(err); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var lastRoute = $route.current; | |
console.log(lastRoute); | |
$scope.$on('$locationChangeSuccess', function (event) { | |
if (lastRoute.$$route.originalPath === $route.current.$$route.originalPath) { | |
$route.current = lastRoute; | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getTotals(items, prop) { | |
return items.reduce( function(a, b) { | |
return a + b[prop]; | |
}, 0); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *ngFor="let row of (sample | searchPipe: input.value)" | |
@Pipe({ | |
name: 'searchPipe', | |
pure: false | |
}) | |
export class SearchPipe implements PipeTransform { | |
transform(sample: any[], searchTerm: string): any[] { | |
if (!searchTerm) return sample; | |
searchTerm = searchTerm.toLowerCase(); | |
if (sample) { |