@angular/core#Injectable TypeScript Examples
The following examples show how to use
@angular/core#Injectable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: leaderboard.service.ts From one-platform with MIT License | 6 votes |
@Injectable({
providedIn: 'root',
})
export class LeaderboardService extends GraphQLModule {
constructor(private apollo: Apollo) {
super();
}
listLHLeaderboard(
type: LeaderboardCategory,
sort: Sort = 'DESC',
search = '',
limit = 10,
offset = 0,
pickCategory?: LeaderboardCategory[]
) {
return this.apollo.query<{
listLHLeaderboard: Pagination<LHLeaderboard[]>;
}>({
query: ListLHLeaderboard,
variables: {
type,
sort,
limit,
offset,
search,
pickCategory,
},
});
}
}
Example #2
Source File: navigation.service.ts From 1hop with MIT License | 6 votes |
@Injectable({
providedIn: 'root'
})
export class NavigationService {
showBackButton = false;
constructor() { }
}
Example #3
Source File: auth.guard.ts From Uber-ServeMe-System with MIT License | 6 votes |
@Injectable({
providedIn: 'root'
})
export class AuthGuard implements CanActivate {
constructor(
public auth: AngularFireAuth,
public user: UserService,
public router: Router
) { }
canActivate(): Promise<boolean> {
return new Promise(resolve => {
this.auth.auth.onAuthStateChanged(user => {
if(!user) this.router.navigate(['login'])
resolve(user ? true : false)
})
})
}
}
Example #4
Source File: index.ts From ngx-tansu with MIT License | 6 votes |
@Injectable()
class WritableStore<T> extends Store<T> implements Writable<T> {
constructor(value: T) {
super(value);
}
set(value: T): void {
super.set(value);
}
update(updater: Updater<T>) {
super.update(updater);
}
}
Example #5
Source File: computervision.service.ts From Angular-Computer-Vision-Azure-Cognitive-Services with MIT License | 6 votes |
@Injectable({
providedIn: 'root'
})
export class ComputervisionService {
baseURL: string;
constructor(private http: HttpClient) {
this.baseURL = '/api/OCR';
}
getAvailableLanguage(): Observable<AvailableLanguage[]> {
return this.http.get<AvailableLanguage[]>(this.baseURL);
}
getTextFromImage(image: FormData): Observable<OcrResult> {
return this.http.post<OcrResult>(this.baseURL, image);
}
}
Example #6
Source File: document-view.service.ts From transformers-for-lawyers with Apache License 2.0 | 6 votes |
@Injectable({
providedIn: 'root'
})
export class DocumentViewService {
private messageSource = new BehaviorSubject('default message');
currentMessage = this.messageSource.asObservable();
constructor() { }
changeMessage(message: string) {
this.messageSource.next(message)
}
}
Example #7
Source File: slider.service.ts From DocumentationWebPage with MIT License | 6 votes |
@Injectable({
providedIn: 'root'
})
export class SliderService {
constructor(private http: HttpClient) {
}
getDataSlides() {
return this.http.get(PATH);
}
}
Example #8
Source File: Queryable.ts From Smersh with MIT License | 6 votes |
@Injectable()
export class UserAutocompleteInput extends QueryableAutocompleteInput {
name = 'user';
source = 'username';
constructor(public service: UsersService) {
super({ service });
}
}
Example #9
Source File: image-api.service.ts From frontend-framework-showdown-2020 with MIT License | 6 votes |
@Injectable({
providedIn: 'root'
})
export class ImageApiService {
constructor(private http: HttpClient) { }
getImages(searchTerm): Observable<string[]> {
return this.http.get<APIResult>(`${API_URL}${searchTerm}`)
.pipe(map(({ images }) => images.map(({ image }: ImageResult) => image)));
}
}
Example #10
Source File: crypto.service.ts From xBull-Wallet with GNU Affero General Public License v3.0 | 6 votes |
@Injectable({
providedIn: 'root'
})
export class CryptoService {
constructor() { }
hashPassword(password: string): string {
return PBKDF2(password, 'WHAT_A_NICE_SALT').toString();
}
encryptText(text: string, secret: string): string {
return AES.encrypt(text, secret).toString();
}
decryptText(text: string, secret: string): string {
return AES.decrypt(text, secret).toString(enc.Utf8);
}
}
Example #11
Source File: gas-api.service.ts From rubic-app with GNU General Public License v3.0 | 6 votes |
@Injectable({
providedIn: 'root'
})
export class GasApiService {
constructor(private readonly httpService: HttpService) {}
/**
* Gets minimum gas price for blockchain to use it in transactions.
* @param blockchain Blockchain to get minimum gas price for.
* @return Observable<BigNumber> Minimum gas price in Wei.
*/
@Cacheable({
maxAge: 15_000
})
public getMinGasPriceInBlockchain(blockchain: BlockchainName): Observable<BigNumber> {
const backendBlockchain = TO_BACKEND_BLOCKCHAINS[blockchain];
return this.httpService
.get<{
[backendBlockchain: string]: number;
}>('min_gas_price', { blockchain: backendBlockchain })
.pipe(
map(minGasPrice => {
return new BigNumber(minGasPrice[backendBlockchain]).multipliedBy(10 ** 9);
}),
catchError(() => {
return of(null);
})
);
}
}
Example #12
Source File: dashboard.service.ts From one-platform with MIT License | 5 votes |
@Injectable({
providedIn: 'root',
})
export class DashboardService extends GraphQLModule {
constructor(private apollo: Apollo) {
super();
}
listLHProjects() {
return this.apollo.query<{ listLHProjects: Pagination<LHProject[]> }>({
query: ListLHProjects,
variables: {
limit: 10000,
},
});
}
listLHProjectBranches(projectId: string) {
return this.apollo.watchQuery<{
listLHProjectBranches: Pagination<{ branch: string }[]>;
}>({
query: ListLHProjectBranches,
variables: {
projectId,
},
});
}
ListLHProjectScores(projectId: string, branch: string, limit = 10) {
return this.apollo.query<{ listLHProjectBuilds: ProjectBranch[] }>({
query: ListLHProjectScores,
variables: {
projectId,
branch,
limit,
},
});
}
listLHLeaderboard(
type: LeaderboardCategory,
branch: string,
projectId: string,
sort: Sort = 'DESC'
) {
return this.apollo.query<{
listLHLeaderboard: Pagination<LHLeaderboard[]>;
getLHRankingOfAProjectBranch: LHLeaderboard;
}>({
query: ListLHLeaderboard,
variables: {
type,
sort,
limit: 5,
offset: 0,
branch,
projectId,
},
});
}
}
Example #13
Source File: configuration.service.ts From 1hop with MIT License | 5 votes |
@Injectable({
providedIn: 'root'
})
export class ConfigurationService {
public CONTRACT_ENS = '1hop.eth';
public GAS_PRICE_URL = 'http://gas-price.api.enterprise.1inch.exchange';
public GAS_PRICE_URL2 = 'https://gasprice.poa.network';
public CORS_PROXY_URL = 'https://corsproxy.1inch.exchange/';
public ONE_SPLIT_CONTRACT_ADDRESS = '0x3F3e18aef051dC2b489CEf138BB9e224F78f7117';
public TOKEN_HELPER_CONTRACT_ADDRESS = '0x1ed7221c4a43632e3ed491a8a28bbebd0b450ad8';
public MCD_POT_CONTRACT_ADDRESS = '0x197E90f9FAD81970bA7976f33CbD77088E5D7cf7';
public FLASH_LOAN_CONTRACT_ADDRESS = '0xBf473d07e3Dabf69a3D6C125E75754dc3C638642';
public EXCHANGE_CONTRACT_ADDRESS = '0xB35Ef14817DBF761127C14c2c7cAafDA9AFcae69';
public PROTOCOL_CONTRACT_ADDRESS = '0xbDC757d6c6A19D41D2E2006222B441860324CeB1';
public HOLDER_CONTRACT_ADDRESS = '0x563200e2e4Cd1cB8114091174C555c5AE2418Fcf';
public TOKEN_CONTRACT_ADDRESS = '0xe2AeE679e50D2f391517E2f4006bA5aB1e6b1D22';
public fastGasPrice = new ethers.utils.BigNumber(Math.trunc(6 * 100)).mul(1e7);
public standardGasPrice = new ethers.utils.BigNumber(Math.trunc(11 * 100)).mul(1e7);
public instantGasPrice = new ethers.utils.BigNumber(Math.trunc(21 * 100)).mul(1e7);
constructor(
private http: HttpClient
) {
setInterval(() => {
try {
this.setGasPrices();
} catch (e) {
}
}, 30000);
this.setGasPrices();
}
async setGasPrices() {
try {
let result;
try {
result = await this.http.get(this.CORS_PROXY_URL + this.GAS_PRICE_URL).toPromise();
} catch (e) {
}
let fastGasPrice,
standardGasPrice,
instantGasPrice;
if (!result || !result['health']) {
result = await this.http.get(this.GAS_PRICE_URL2).toPromise();
}
fastGasPrice = result['fast'] * 110 * 1e9 / 100;
standardGasPrice = result['standard'] * 110 * 1e9 / 100;
instantGasPrice = result['instant'] * 110 * 1e9 / 100;
this.fastGasPrice = ethers.utils.bigNumberify(Math.trunc(fastGasPrice));
this.standardGasPrice = ethers.utils.bigNumberify(Math.trunc(standardGasPrice));
this.instantGasPrice = ethers.utils.bigNumberify(Math.trunc(instantGasPrice));
} catch (e) {
// console.error(e);
}
}
}
Example #14
Source File: configuration.service.ts From 1x.ag with MIT License | 5 votes |
@Injectable({
providedIn: 'root'
})
export class ConfigurationService {
public ONE_SPLIT_CONTRACT_ADDRESS = '0xDFf2AA5689FCBc7F479d8c84aC857563798436DD';
public TOKEN_HELPER_CONTRACT_ADDRESS = '0x1ed7221c4a43632e3ed491a8a28bbebd0b450ad8';
public ETH_ADDRESS = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE';
public ETHDAI2x = '0x7778d1011e19C0091C930d4BEfA2B0e47441562A';
public HOLDER_ONE_AAVE_COMPOUND = '0x96930e5BBaa0A53019f601C6c5E2563c910988fd';
public CONTRACT_ENS = '1xAggregator.eth';
public GAS_PRICE_URL = 'http://gas-price.api.enterprise.1inch.exchange';
public GAS_PRICE_URL2 = 'https://gasprice.poa.network';
public CORS_PROXY_URL = 'https://corsproxy.1inch.exchange/';
public fastGasPrice = new ethers.utils.BigNumber(Math.trunc(6 * 100)).mul(1e7);
public standardGasPrice = new ethers.utils.BigNumber(Math.trunc(11 * 100)).mul(1e7);
public instantGasPrice = new ethers.utils.BigNumber(Math.trunc(21 * 100)).mul(1e7);
constructor(
private http: HttpClient
) {
setInterval(() => {
try {
this.setGasPrices();
} catch (e) {
}
}, 30000);
this.setGasPrices();
}
async setGasPrices() {
try {
let result;
try {
result = await this.http.get(this.CORS_PROXY_URL + this.GAS_PRICE_URL).toPromise();
} catch (e) {
}
let fastGasPrice,
standardGasPrice,
instantGasPrice;
if (!result || !result['health']) {
result = await this.http.get(this.GAS_PRICE_URL2).toPromise();
}
fastGasPrice = result['fast'] * 110 * 1e9 / 100;
standardGasPrice = result['standard'] * 110 * 1e9 / 100;
instantGasPrice = result['instant'] * 110 * 1e9 / 100;
this.fastGasPrice = ethers.utils.bigNumberify(Math.trunc(fastGasPrice));
this.standardGasPrice = ethers.utils.bigNumberify(Math.trunc(standardGasPrice));
this.instantGasPrice = ethers.utils.bigNumberify(Math.trunc(instantGasPrice));
} catch (e) {
// console.error(e);
}
}
}
Example #15
Source File: 1inch.api.service.ts From gnosis.1inch.exchange with MIT License | 5 votes |
@Injectable({
providedIn: 'root'
})
export class OneInchApiService {
private url = 'https://gnosis.api.enterprise.1inch.exchange/v3.0/1';
constructor(private http: HttpClient) {
}
public getQuote$(
fromTokenAddress: string,
toTokenAddress: string,
amount: string,
): Observable<Quote> {
let params = new HttpParams();
params = params.append('fromTokenAddress', fromTokenAddress);
params = params.append('toTokenAddress', toTokenAddress);
params = params.append('amount', amount);
const url = this.url + '/quote';
return this.http.get<Quote>(url, { params }).pipe(
delayedRetry(1000)
);
}
public getSwapData$(
fromTokenAddress: string,
toTokenAddress: string,
amount: string,
fromWalletAddress: string,
slippage = '1',
disableEstimate = false,
): Observable<SwapData> {
let params = new HttpParams();
params = params.append('fromTokenAddress', fromTokenAddress);
params = params.append('toTokenAddress', toTokenAddress);
params = params.append('amount', amount);
params = params.append('fromAddress', fromWalletAddress);
params = params.append('slippage', slippage);
params = params.append('disableEstimate', String(disableEstimate));
const url = this.url + '/swap';
return this.http.get<SwapData>(url, { params }).pipe(
delayedRetry(1000)
);
}
public getTokens$(): Observable<ISymbol2Token> {
const url = this.url + '/tokens';
return this.http.get<{tokens: ISymbol2Token}>(url).pipe(
timeout(5000),
delayedRetry(1000)
).pipe(
map((x) => x.tokens)
);
}
}
Example #16
Source File: home-service.service.ts From Uber-ServeMe-System with MIT License | 5 votes |
@Injectable({
providedIn: 'root'
})
export class HomeServiceService {
private homeServiceCollection = this.afs.collection<HomeService>('HomeServices')
constructor(
private afs: AngularFirestore,
private afAuth: AngularFireAuth
) { }
getServices() {
return this.homeServiceCollection.stateChanges().pipe(
map(actions => {
return actions.map(a => {
const data = a.payload.doc.data()
const id = a.payload.doc.id
return {id, ...data}
})
})
)
}
addService(homeservice: HomeService) {
return this.homeServiceCollection.add(homeservice)
}
getService(id: string) {
return this.homeServiceCollection.doc<HomeService>(id).valueChanges()
}
updateService(id: string, homeService: HomeService) {
// TODO: is that enough?
return this.homeServiceCollection.doc<HomeService>(id).update(homeService)
}
updateLocation(newLocation: any) {
this.afs.collection('/HomeServices', ref => ref.where('vendorId', '==', this.afAuth.auth.currentUser.uid))
.get().toPromise().then(res => {
let batch = this.afs.firestore.batch()
res.docs.forEach((doc) => {
const docRef = this.afs.collection('HomeServices').doc(doc.id).ref
batch.update(docRef, {location: newLocation})
})
batch.commit().then(() => {
console.log(`updated all documents inside Homeserivcs`)
})
})
}
deleteProduct(id: string) {
return this.homeServiceCollection.doc(id).delete()
}
}
Example #17
Source File: ngx-photo-editor.service.ts From ngx-photo-editor with MIT License | 5 votes |
@Injectable({
providedIn: 'root'
})
export class NgxPhotoEditorService {
constructor() {
}
}