Skip to content

Redundant and cryptic usage of ng-container in many places #6453

Answered by wzhudev
ducatyb asked this question in Q&A
Discussion options

You must be logged in to vote

Lots of properties including nzPercent accept TemplateRef or string. nzStringTemplateOutlet is for dealing with this situation.

<ng-container *nzStringTemplateOutlet="formatter; context: { $implicit: nzPercent }; let formatter">
   {{ formatter(nzPercent) }}
</ng-container>

In this example, if nzPercent is a template, we will render it and inject the context. Otherwise, we would directly render {{ formatter(nzPercent) }}.

In conclusion, we could not simplify this.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ducatyb
Comment options

Answer selected by ducatyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants