In Angular 2 templates safe operator ?.
works, but not in component.ts
using TypeScript 2.0. Also, safe navigation operator (!.
) doesn't work.
For example:
This TypeScript
if (a!.b!.c) { }
compiles to this JavaScript
if (a.b.c) { }
But when I run it, I get the follow error:
Cannot read property 'b' of undefined
Is there any alternative to the following?
if (a && a.b && a.b.c) { }
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…