Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在angular上使用纯javascript库hashids.js?_Javascript_Angular_Typescript_Hashids - Fatal编程技术网

如何在angular上使用纯javascript库hashids.js?

如何在angular上使用纯javascript库hashids.js?,javascript,angular,typescript,hashids,Javascript,Angular,Typescript,Hashids,我试着直接导入库 import * as hash from '../../../../node_modules/hashids'; 我试过这个密码 let id = hash.encode(this.studentDocument.student_id_number); console.log(id); 但它抛出了这个错误,悲哀 _node_modules_hashids__WEBPACK_IMPORTED_MODULE_2__.encode is not a function 我甚至试

我试着直接导入库

import * as hash from '../../../../node_modules/hashids';
我试过这个密码

let id = hash.encode(this.studentDocument.student_id_number); console.log(id);
但它抛出了这个错误,悲哀

_node_modules_hashids__WEBPACK_IMPORTED_MODULE_2__.encode is not a function
我甚至试过这个

declare var hash:any;
但它抛出了这个错误

hash is not defined
任何提示都将不胜感激!
(续)

您需要创建hashids对象的新实例

import * as hash from 'hashids';

const hashids = new hash();
const id = hashids.encode(348029348);
console.log(id);

您需要创建hashids对象的新实例

import * as hash from 'hashids';

const hashids = new hash();
const id = hashids.encode(348029348);
console.log(id);

您是否尝试将
import*替换为“../../../../../node_modules/hashid”中的散列通过
要求('hashids')
?像这样的,先生?require('hashids');如何访问这些方法?谢谢你的回复!在require之后,只需放入
声明var hashids:any然后作为文档使用。它抛出此错误,错误引用错误:未定义哈希ID。我想它确实有它的怪癖。谢谢再次回复,先生!您是否尝试将
import*替换为“../../../../../node_modules/hashid”中的散列通过
要求('hashids')
?像这样的,先生?require('hashids');如何访问这些方法?谢谢你的回复!在require之后,只需放入
声明var hashids:any然后作为文档使用。它抛出此错误,错误引用错误:未定义哈希ID。我想它确实有它的怪癖。谢谢再次回复,先生!wingnod爵士,我把代码扔给构造函数,减去导入,但是这个错误突然出现了。无法将“new”与类型缺少调用或构造签名的表达式一起使用。它没有将import*作为“HashId”的哈希使用;但是使用“../../../../node_modules/hashids/dist/hashids.min.js”中的import*作为散列;wingnod爵士,我把代码扔给构造函数,减去导入,但是这个错误突然出现了。无法将“new”与类型缺少调用或构造签名的表达式一起使用。它没有将import*作为“HashId”的哈希使用;但是使用“../../../../node_modules/hashids/dist/hashids.min.js”中的import*作为散列;