This file contains hidden or 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
interface IRouteConfigData { | |
reuse: boolean; | |
} | |
interface ICachedRoute { | |
handle: DetachedRouteHandle; | |
data: IRouteConfigData; | |
} | |
@Injectable() |
This file contains hidden or 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 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) => |
This file contains hidden or 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 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)); |
This file contains hidden or 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
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"); |
This file contains hidden or 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 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 |
This file contains hidden or 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 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()); |
This file contains hidden or 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
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 : |
This file contains hidden or 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 { | |
ComponentCanDeactivate | |
} from './pending-changes.guard'; | |
import { | |
HostListener | |
} from '@angular/core'; | |
import { | |
Observable | |
} from 'rxjs/Observable'; | |
export class MyComponent implements ComponentCanDeactivate { |
This file contains hidden or 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
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(); | |
} |
This file contains hidden or 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 { | |
Injectable | |
} from '@angular/core'; | |
import { | |
Router, | |
RouterEvent, | |
NavigationEnd | |
} from '@angular/router'; | |
/** A router wrapper, adding extra functions. */ | |
@Injectable() |
NewerOlder