NestJS中是否可以从html中获取内部文本

问题描述 投票:0回答:1

我向我的数据库发送了一个原始的

html
。但我想创建一个
slug
并且为此,我更愿意使用
innerText
而不是 html。我想做

    const div = document.createElement('div');
    div.innerHTML = data.description;

    let slug = slugify(div.innerText);

但是 NestJS 会抛出错误。有没有什么方法可以让我从这个原始的

innerText
中获得
html

html nestjs
1个回答
0
投票

使用 Nextjs,

document
对象及其方法(如
createElement
innerText
)特定于浏览器环境,在服务器端不可用。

为什么不创建一个字符串?

const newDiv = `<div>${data.description}</div>`
....
© www.soinside.com 2019 - 2024. All rights reserved.