如何生成角度为2的UUID? [英] How to generate UUID with angular 2?

查看:108
本文介绍了如何生成角度为2的UUID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Angular 2进行注册: 名,姓,电子邮件和密码.

I'm using Angular 2 for a signup form: first name, last name, email and password.

提交后,数据将通过API调用存储在数据库中(nodeJs和mongo),并生成JWT令牌,该令牌将被发送回客户端.

After submit, the data is being stored via API call in a database (nodeJs and mongo) and generates a JWT Token which is sent back to the client.

现在,我应该添加/生成一个UUID(通用唯一标识符).因为我以前从未做过这种功能,所以我需要一种方法和想法/解决方案如何实现这一点... JWT令牌是否可以替代UUID?如果是,那就足够了.

Now I should add/generate an UUID (Universal Unique Identifier). As I never have done this kind of feature before, I need an approach and idea/solution how to achieve this... would the JWT Token be a kind of alternative to UUID? If yes, this would be enough.

否则,我希望避免对表单或其功能进行任何大的更改.

Otherwise I would prefer to avoid any big changes on the form or its functionality.

我一直在搜索,但是没有找到有用的解决方案.我尝试了npm软件包angular2-uuid,但是在将其安装为依赖项之后,ng build -prod抛出了一个不清楚的错误.

I Have been searching, but didn't find a useful solution. I tried the npm package angular2-uuid, but after installing it as dependency, the ng build -prod throws an error which isn't clear.

import { UUID } from 'angular2-uuid';
....
let uuid = UUID.UUID();

错误:

./〜/@ angular/flex-layout/@ angular/flex-layout.es5.js模块中的错误 构建失败:错误:ENOENT:没有此类文件或目录,请打开 '/用户/用户名/dev/app/node_modules/@ angular/flex- 布局/@angular/flex-layout.es5.js'@ ./src/$$_gendir/app/app.module.ngfactory.ts 25:0-44 @ ./src/main.ts @ 多个webpack-dev-server/client? http://localhost:4200 ./src/main.ts

ERROR in ./~/@angular/flex-layout/@angular/flex-layout.es5.js Module build failed: Error: ENOENT: no such file or directory, open '/Users/username/dev/app/node_modules/@angular/flex- layout/@angular/flex-layout.es5.js' @ ./src/$$_gendir/app/app.module.ngfactory.ts 25:0-44 @ ./src/main.ts @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

有什么想法或提示吗?

推荐答案

问题已解决.解决方案:我发现当我确实通过命令行安装软件包angular2-uuid时,它被自动存储在package.json中,紧接在软件包@angular/flex-layout之前/上方.

Issue fixed. Solution: I found out that when I did install the package angular2-uuid via command-line, it was automatically stored in package.json directly before/over the package: @angular/flex-layout.

由于无法以某种方式清除错误,所以我只是将其删除到了package.json中的其他位置,该错误消失了.一切正常.

As the error was in a way not clear, I just did remove it to other position in the: package.json and the error is gone. everything works fine.

这篇关于如何生成角度为2的UUID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆