How do I use pure javascript library, hashids.js on angular?

♀尐吖头ヾ 提交于 2019-12-11 14:18:48

问题


I tried importing the library directly

import * as hash from '../../../../node_modules/hashids';

and tried this code

let id = hash.encode(this.studentDocument.student_id_number); console.log(id);

But it throws this error, sad.

_node_modules_hashids__WEBPACK_IMPORTED_MODULE_2__.encode is not a function

I even tried this

declare var hash:any;

But it throws this error

hash is not defined

Any tip would be greatly appreciated! (a cont. of this post)


回答1:


You need to create a new instance of the hashids object.

import * as hash from 'hashids';

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


来源:https://stackoverflow.com/questions/52252611/how-do-i-use-pure-javascript-library-hashids-js-on-angular

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!