angular Big.js集成获取类型
在我工作的应用程序中,我必须 使用Big.js 为了整合它,我遵循以下步骤 1) 使用创建一个typings.d.tsangular Big.js集成获取类型,angular,typescript,Angular,Typescript,在我工作的应用程序中,我必须 使用Big.js 为了整合它,我遵循以下步骤 1) 使用创建一个typings.d.ts declare module '*.mjs'; 2) 创建一个提供者 import Big from 'big.js/big.mjs'; { provide: 'BigJs', useValue: Big }, 3) 创建服务 从“@angular/core”导入{Inject,Injectable} @Injectable() export class BigjsServ
declare module '*.mjs';
2) 创建一个提供者
import Big from 'big.js/big.mjs';
{ provide: 'BigJs', useValue: Big },
3) 创建服务
从“@angular/core”导入{Inject,Injectable}
@Injectable()
export class BigjsService {
readonly TO_FIXED = 2;
constructor(@Inject('BigJs') private bj: any) {}
toStr(num: number | string): string {
return this.bj(num).toFixed(this.TO_FIXED);
}
op(num: number | string): any {
return this.bj(num);
}
}
现在我想在服务中输入Big
正确的方法是什么
我想
import { Inject, Injectable } from '@angular/core';
import Big from 'big.js/big.mjs';
type MyBig = typeof Big;
@Injectable()
export class BigjsService {
readonly TO_FIXED = 2;
constructor(@Inject('BigJs') private bj: MyBig) {}
toStr(num: number | string): string {
return this.bj(num).toFixed(this.TO_FIXED);
}
op(num: number | string): MyBig {
return this.bj(num);
}
}
这条路对吗
它可以工作,但由于服务已导入
很多时候,我担心big.mjs是进口的
也有很多次:(