[英]Angular - Ternary operator with a ternary operator response
我的 angular HTML 中有一個三元運算符。 我在格式化時遇到困難。 如果該值等於文件長度,它應該返回Good
,如果不是,我需要檢查一些自定義值。 我檢查自定義值是否存在( custom 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' }}
也許你的意思是這樣(使用 ${var})
{{ value == files.length ? 'Good' : customs?.album_title ? `My Text ${customs.album_title}` : 'String Two' }}
我不確定,但我認為 HTML 模板上的Angular尚不支持模板文字。
所以現在,你可以嘗試通過字符串連接來解決它
{{ value == files.length ? 'Good' : customs?.album_title ? ('My Text ' + customs.album_title) : 'String Two' }}
你可以試試這個:
{{ value == files.length ? 'Good' : (customs?.album_title ? (('My Text ') + customs.album_title) : 'String Two') }}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.