Skip to content

Instantly share code, notes, and snippets.

View patelatit53's full-sized avatar

ap patelatit53

  • Toronto,Canada
View GitHub Profile
interface IRouteConfigData {
reuse: boolean;
}
interface ICachedRoute {
handle: DetachedRouteHandle;
data: IRouteConfigData;
}
@Injectable()
var reduce = users.reduce((unique, val) => {
if (!unique.some(data => data.id === val.id && data.name === val.name)) {
unique.push(o);
}
return unique;
}, []);
const uniqueValue = (arr, key) =>
arr.reduce(
(prev, curr) =>
var setuniq = [...new Set(array)];
var set1 = Array.from(
users.reduce((m, t) => m.set(t.id, t), new Map()).values()
);
const uniq = new Set(users.map(e => JSON.stringify(e)));
const set2 = Array.from(uniq).map(e => JSON.parse(e));
function getUniqueListBy(arr, key) {
return [...new Map(arr.map(item => [item[key], item])).values()];
}
const arr1 = getUniqueListBy(users, "id");
var reduced = [...array.reduce((p, c) => p.set(c, true), new Map()).keys()];
const arr2 = getUniqueListBy(users, "name");
var filteruniquebyID = users.filter(
(v, i, a) => a.findIndex(t => t.id === v.id) === i
);
var filteruniquebyIDName = users.filter(
(v, i, a) => a.findIndex(t => t.id === v.id || t.name === v.name) === i
);
var filteruniquebyIDName1 = users.filter(
(v, i, a) => a.findIndex(t => JSON.stringify(t) === JSON.stringify(v)) === i
var uniqueUsersByID = _.uniqBy(users, "id"); //removed if had duplicate id
var uniqueUsers = _.uniqWith(users, _.isEqual); //removed complete duplicates
const uniquewithMultipleProperties = _.uniqWith(
users,
(a, b) => a.id === b.id || a.name === b.name
);
var result = _.uniqBy(users, v => [v.id, v.name].join());
export interface ComponentCanDeactivate {
canDeactivate: () => boolean | Observable < boolean > ;
}
@Injectable()
export class PendingChangesGuard implements CanDeactivate < ComponentCanDeactivate > {
canDeactivate(component: ComponentCanDeactivate): boolean | Observable < boolean > {
// if there are no pending changes, just allow deactivation; else confirm first
return component.canDeactivate() ?
true :
import {
ComponentCanDeactivate
} from './pending-changes.guard';
import {
HostListener
} from '@angular/core';
import {
Observable
} from 'rxjs/Observable';
export class MyComponent implements ComponentCanDeactivate {
export class AppModule {
constructor(private routerExtService: RouterExtService) {}
//...
}
// Using in SomeComponent
export class SomeComponent implements OnInit {
constructor(private routerExtService: RouterExtService, private location: Location) {}
back(): void {
this.location.back();
}
import {
Injectable
} from '@angular/core';
import {
Router,
RouterEvent,
NavigationEnd
} from '@angular/router';
/** A router wrapper, adding extra functions. */
@Injectable()