question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Enable Nullish Coalescing operator in angular template

See original GitHub issue

πŸš€ feature request

Relevant Package

This feature request is for @angular/core

Description

What do you think about enabling Nullish Coalescing also in angular template?

I often write for example something like this:

<span [title]="variable != null ? variable : ''">

s.t if variable = 3, title = β€˜3’ if variable = 0, title = β€˜0’ if variable = null, title = β€˜β€™, meaning the html tooltip title is hidden

Describe the solution you’d like

It would be nice in my opinion to write something like:

<span [title]="variable ?? ''">

to obtain the same results with a less verbose syntax.

It may be also helpful in other situations, in template interpolation {{ … }}, etc

What do you think? Thanks!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:169
  • Comments:15

github_iconTop GitHub Comments

13reactions
janpauldahlkecommented, Jan 8, 2021

bump*

7reactions
snebjorncommented, Feb 9, 2021

The nullish coalescing operator would be a much preferred way to handle the current AsyncPipe workaround for null | undefined

<tag
  [myInput]="(myObs$ | async) ?? fallbackValue"
>
</tag>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Nullish Coalescing support in Angular template
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null orΒ ......
Read more >
Angular Nullish Coalescing Operator (??) - ConcretePage.com
The nullish coalescing operator (??) is a logical operator that has following syntax. ... If left-hand side operand is null or undefined ,...
Read more >
Nullish Coalescing support in Angular template - Avinash Dalvi
The nullish coalescing operator (??) is a logical operator that returns its right-hand side operand when its left-hand side operand is null or...
Read more >
NG8102: Nullish coalescing not nullable - Angular
This diagnostic detects a useless nullish coalescing operator ( ?? ) characters in Angular templates. Specifically, it looks for operations where the inputΒ ......
Read more >
Angular Equivalent of Null Coalescing Operator in HTML ...
Note: If you enable this.item.ProductName="P-Name"; this line it will show "P-Name" otherwise it will show "P-Type"Β ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found