0

我的角度 HTML 中有一个三元运算符。我在格式化时遇到困难。如果该值等于文件长度,它应该返回Good,如果不是我需要检查一些自定义值。我检查自定义值是否存在 ( customs?.album_title),然后确定要显示的内容。如果两个选项都是字符串,它完全可以正常工作。但是,我需要My Text预先设置customs.album_title值,但我不完全确定该怎么做。正如您在下面的示例中看到的(这自然是不正确的),结果将是customs?.album_title一个字符串,与My Text+ 相对,无论customs.album_title值是什么。

任何帮助将不胜感激。

{{ value == files.length ? 'Good' : customs?.album_title ? 'My Text customs.album_title' : 'String Two' }}
4

2 回答 2

0

也许你的意思是这样(使用 ${var})

{{ value == files.length ? 'Good' : customs?.album_title ? `My Text ${customs.album_title}` : 'String Two' }}

我不确定,但我认为Angular 在 HTML 模板上尚不支持模板文字。

所以现在,你可以尝试通过字符串连接来解决它

{{ value == files.length ? 'Good' : customs?.album_title ? ('My Text ' + customs.album_title) : 'String Two' }}
于 2021-05-11T12:55:44.043 回答
0

你可以试试这个:

{{ value == files.length ? 'Good' : (customs?.album_title ? (('My Text ') + customs.album_title) : 'String Two') }}
于 2021-05-11T13:42:57.560 回答