This source code has @Input
properties that end with a !
(此源代码具有以@Input
结尾的@Input
属性!
)
@Input() token!:StripeToken
Why is it useful to have the !
(为什么拥有!
) in this case?(在这种情况下?) Some of the comments have noted that it is a non null assertion operator, but why is it useful (Or perhaps not useful) to have that in this particular scenario?(一些评论指出,它是一个非null的断言运算符,但是为什么在这种特殊情况下使用它是有用的(或可能没有用)?)
I think the answer to this is that for Angular @Input
properties having the non null assertion at the end of the property never makes sense but I wanted to see what the rest of you thought?(我认为这的答案是,对于在属性末尾具有非null断言的Angular @Input
属性,从没有意义,但我想看看您其余部分的想法吗?)
Update(更新资料)
I tried it on a new Angular project and I get this error:(我在新的Angular项目上尝试了此操作,但出现此错误:)
A definite assignment assertion '!'(确定分配断言“!”) is not permitted in this context.ts(1255)(ts(1255)在这种情况下是不允许的)
So I don't think that it ever makes sense to inlude the !
(因此,我认为包含!
) operator on an @Input
property.(@Input
属性上的运算符。) Here's a screenshot:(这是屏幕截图:)
ask by Ole translate from so