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
#Create a CustomLazyAPIKeyLoader class file and extends MapsAPILoader | |
import { GoogleMapsScriptProtocol, LAZY_MAPS_API_CONFIG, LazyMapsAPILoaderConfigLiteral, MapsAPILoader } from '@agm/core'; | |
import { DocumentRef, WindowRef } from '@agm/core/utils/browser-globals'; | |
import { Inject, Injectable } from '@angular/core'; | |
import { AppGlobals } from './../../Common/Services/app.global'; | |
@Injectable() | |
export class CustomLazyAPIKeyLoader extends MapsAPILoader { |
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
Here are steps to generate google restrict key: | |
1. Go to site: https://console.developers.google.com/projectselector/apis/credentials?supportedpurview=project | |
2. Log in to the page with your Gmail account | |
3. Create or Select your project. | |
a. If you already created a project before then you can select that one. | |
b. Else click on create button to create a project. |
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 { Inject, Injectable, Optional } from '@angular/core'; | |
import { DateAdapter, NativeDateAdapter } from '@angular/material'; | |
export class AppDateAdapter extends NativeDateAdapter { | |
parse(value: any): any { | |
if (value) { | |
const timestamp = typeof value === 'number' ? value : Date.parse(value); | |
let date_regex = /([0-9]{2}[0-9]{1}\d{1})-([0]{1}[1-9]{1}|[1]{1}[0-2]{1})-([0]{1}[1-9]{1}|[12]{1}\d{1}|[3]{1}[01]{1})/; // Can you own regex or remove it. | |
if (date_regex.test(value)) { | |
return isNaN(timestamp) ? null : new Date(timestamp); |
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 algorithm will first find the smallest element in the array and swap it with the element in the first position, | |
then it will find the second smallest element and swap it with the element in the second position, | |
and it will keep on doing this until the entire array is sorted. | |
// Method to find Minimum Value and Minimum Index | |
function findMinIndex(arr, startIndex) { | |
var minIndex = startIndex; | |
var minValue = arr[startIndex]; |
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
function printFib(count) { | |
var n1 = 0; // first char is 0 of fibonacci series | |
var n2 = 1; // seconds char is also fixed '1' | |
var output = ""; | |
output = n1 + " " + n2; | |
// loop start from 2 because we know the first and second chars | |
for (var i = 2; i < count; i++) { |
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
//First non repeating char : How could you find the first non repeating char in a string? | |
function firstNonRepeatChar(s) { | |
for (var i = 0; i < s.length; i++) { | |
var letter = s.charAt(i); | |
if (s.substring(s.indexOf(letter) + 1, s.length).indexOf(letter) == -1) { | |
console.log(letter); | |
break; | |
} | |
} | |
} |
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
1. Compare two arrays contains Object type element | |
2. Below we are checking based on one property "id" | |
3. remove duplicate items | |
(<any>Array.prototype).unique = function () { | |
var a = this.concat(); | |
for (var i = 0; i < a.length; ++i) { | |
for (var j = i + 1; j < a.length; ++j) { | |
if (a[i].id === a[j].id) // checking based on id property |
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
(<any>window).gapi.load('auth2', () => { | |
(<any>window).gapi.auth2.init().then(() => { | |
var auth2 = (<any>window).gapi.auth2.getAuthInstance(); | |
auth2.signOut().then((res) => { | |
if (response.responseCode == 'S0001') { | |
window.location.href = '/login'; | |
} | |
}) | |
.catch((err) => { console.log('error is ', 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
navigator.onLine --> Check for Internet connection | |
navigator.cookieEnabled --> Check for Cookies Enabled. | |
if (navigator.onLine == false || navigator.cookieEnabled == false) { | |
this._router.navigate(['/offline']); // create a new page named like "offline" & redirect to that page | |
this.util.isOffline = true; // for custom use to activate route | |
} |
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
getFile(id) { | |
this.newWindow = window.open(); | |
this.downloadDocument(id).subscribe(response => { // API - this.downloadDocument(id) | |
this.util.removeLoader(); | |
this.downloadFileFromBlob(response["_body"]); | |
}, error => { }) | |
} |
OlderNewer