1

We undoubtedly use safe navigation in string interpolation ({{}}) to safely navigate values in a nested object with checking nulls or undefined. I have a question that, is it okay to use safe navigation also for:

  1. ngIf
  2. ngFor
  3. ngModel
  4. ngClass
  5. and other html property bindings like [disabled], [style], etc.

For which scenarios should I use and not?

Faizan Saiyed
  • 804
  • 3
  • 17
  • 33
  • What do you mean "should" use it? Why do you think it shouldn't be used in any of the above? – Kurt Hamilton Feb 28 '20 at 07:40
  • Through the official docs and Googling, I found all the statements using this operator with string interpolation only. – Faizan Saiyed Feb 28 '20 at 07:44
  • Considering that safe navigation has only been in since v9, I'm not surprised. If you infer from the docs that typescript can be written in these places, then it makes sense to also use the operators that come with typescript? – Kurt Hamilton Feb 28 '20 at 07:50

1 Answers1

2

We can use ? in every place you have mentioned, except two way binding ngModel. You could use when you are using [ngModel] but not when using [(ngModel)]