Javascript Mathjs';全局配置是只读的';?
我使用Angular 8和math.js库进行大数操作 我刚刚更新了math.js的版本,从5.4.0到6.2.3 我在组件中使用math.js的方式如下:Javascript Mathjs';全局配置是只读的';?,javascript,angular,mathjs,Javascript,Angular,Mathjs,我使用Angular 8和math.js库进行大数操作 我刚刚更新了math.js的版本,从5.4.0到6.2.3 我在组件中使用math.js的方式如下: import * as mathjs from 'mathjs'; constructor() { mathjs.config({ number: 'BigNumber', precision: 128 }); } 更新后突然出现新错误 ERROR Error: The global config is readonly. Pl
import * as mathjs from 'mathjs';
constructor() {
mathjs.config({ number: 'BigNumber', precision: 128 });
}
更新后突然出现新错误
ERROR Error: The global config is readonly.
Please create a mathjs instance if you want to change the default configuration.
Example:
import { create, all } from 'mathjs';
const mathjs = create(all);
mathjs.config({ number: 'BigNumber' });
我尝试从“mathjs”导入{create,all},但这些方法根本不存在
此问题的解决方法是什么?不确定是否解决了您的问题,但根据错误,您应该创建一个新实例,稍后使用,如下所示-
import { create, all } from 'mathjs';
const mathjs = new create(all);
mathjs.config({ number: 'BigNumber' });
不确定是否解决了您的问题,但根据错误,您应该创建一个新实例,稍后使用,如下所示-
import { create, all } from 'mathjs';
const mathjs = new create(all);
mathjs.config({ number: 'BigNumber' });
过了一段时间,我终于找到了解决办法 首先,我需要删除行:
import * as mathjs from 'mathjs';
这一行不再生成seance,因为我们需要创建具有此名称的变量,该变量将是具有新配置的mathjs的新实例
import { create, all, MathJsStatic } from 'mathjs';
private mathjs: Partial<MathJsStatic>;
constructor() {
this.mathjs = create(all, { number: 'BigNumber', precision: 128 });
}
从'mathjs'导入{create,all,MathJsStatic};
私人数学:部分;
构造函数(){
this.mathjs=create(all,{number:'BigNumber',精度:128});
}
如果我们在所有应用程序上都需要相同的mathjs配置,最好的方法是创建一个服务并在任何地方使用相同的实例。过了一段时间,我终于找到了解决方案 首先,我需要删除行:
import * as mathjs from 'mathjs';
这一行不再生成seance,因为我们需要创建具有此名称的变量,该变量将是具有新配置的mathjs的新实例
import { create, all, MathJsStatic } from 'mathjs';
private mathjs: Partial<MathJsStatic>;
constructor() {
this.mathjs = create(all, { number: 'BigNumber', precision: 128 });
}
从'mathjs'导入{create,all,MathJsStatic};
私人数学:部分;
构造函数(){
this.mathjs=create(all,{number:'BigNumber',精度:128});
}
如果我们在所有应用程序上都需要相同的mathjs配置,最好的方法是创建一个服务,并在任何地方使用相同的实例。是的,我尝试过,但由于我没有更新@types/mathjs,所以出现了错误。现在我有两个关于行const mathjs=newcreate(all)的问题;1) 隐藏名称:“mathjs”(无隐藏变量)2)(属性)create:(factories:FactoryFunctionMap,config:ConfigOptions)=>Partial import create需要2个参数,但得到了1.ts(2554)年,我尝试了这一点,但因为我没有更新@types/mathjs,所以出现了错误。现在我有两个关于行const mathjs=newcreate(all)的问题;1) 隐藏名称:“mathjs”(无隐藏变量)2)(属性)create:(工厂:FactoryFunctionMap,配置:ConfigOptions)=>部分导入创建预期的2个参数,但得到1.ts(2554)