I tried the packages https://www.npmjs.com/package/uuid-generator-ts and https://www.npmjs.com/package/@types/uuid. But I am getting an error, if I install these packages,
Nothing to do with Angular itself, you can get uuid from one of the popular npm package such as this:
https://www.npmjs.com/package/uuid
The code looks like this:
import * as uuid from 'uuid';
const myId = uuid.v4();
However, the uuid
package does not define a uuid
class (type); it just provides utilities for generating and parsing UUIDs as string
s, and for converting between string
and byte array representations. So you will not be able to use the type system to ensure that values are valid UUIDs.