问题描述
我遇到了解析的问题,这是用Elvis运算符解决的,但是如果我有包含正斜杠的键,我就不能使用Elvis运算符,因为我必须把那个键放到方括号中。
I had problems with parsing, which is solved with Elvis operator, but if I have key that contains forward slash, I cant use Elvis operator because I have to put that key into square brackets.
如果密钥很简单(firstname)
Works if key is simple like this ( "firstname" )
{{ data?.record?.firstname }}
如果key有这样的前括号(name / first),则不起作用
Does not work if key has forward brackets like this ( "name/first" )
{{ data?.record?['name/first']}}
如果我使用方括号,似乎Elvis不可用。
It seems that Elvis is not available if I use square brackets.
任何解决方法?也许是一种逃避冲突的方法。符号如下:
Any workaround? Maybe a way to escape forward slash in . notation like this:
{{ data?.record?.name\\/first }}
推荐答案
Elvis运算符仅适用于。
不适用于 []
等其他解除引用运算符。
The Elvis operator is only available for the .
not for other dereference operators like []
.
作为解决方法使用
{{ data?.record ? data.record['name/first'] : null}}
这篇关于Angular2使用带有正斜杠的对象键上的Elvis运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!