gpt4 book ai didi

angular - 如何将代码片段放入 Angular 5 *.component.html

转载 作者:行者123 更新时间:2023-12-02 11:21:31 24 4
gpt4 key购买 nike

我目前正在做一个 Angular 5 项目。我在这里面临一个棘手的问题。

我想通过使用 <code> 在我的 component.html 文件中包含一些代码片段标签。但这样做似乎会在 Angular 方面返回处理错误。所以我尝试将代码放在 *.component.ts 文件的变量中,并使用数据绑定(bind),显示如下代码:

<code_tag>{{my_code_snippet}}</code_tag>

但现在的问题是代码总是以字符串形式出现,并且格式不正确(例如,如果它是 JSON 代码)

我应该如何解决这个问题?

最佳答案

你可以告诉 Angular 忽略 <code> 中的字符串。带有 ngNonBindable 的元素属性

<code ngNonBindable>
console.log("no output");
</code>

关于angular - 如何将代码片段放入 Angular 5 *.component.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49254952/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com