OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to check whether <ng-content> is empty? (in Angular 2+ till now)

  • Thread starter Thread starter Slawomir Dadas
  • Start date Start date
S

Slawomir Dadas

Guest
Suppose I have a component:

Code:
@Component({
    selector: 'MyContainer',
    template: `
    <div class="container">
        <!-- some html skipped -->
        <ng-content></ng-content>
        <span *ngIf="????">Display this if ng-content is empty!</span>
        <!-- some html skipped -->
    </div>`
})
export class MyContainer {
}

Now, I would like to display some default content if <ng-content> for this component is empty. Is there an easy way to do this without accessing the DOM directly?

<p>Suppose I have a component:</p>

<pre class="lang-js prettyprint-override"><code>@Component({
selector: 'MyContainer',
template: `
<div class="container">
<!-- some html skipped -->
<ng-content></ng-content>
<span *ngIf="????">Display this if ng-content is empty!</span>
<!-- some html skipped -->
</div>`
})
export class MyContainer {
}
</code></pre>

<p>Now, I would like to display some default content if <code><ng-content></code> for this component is empty. Is there an easy way to do this without accessing the DOM directly?</p>
 

Latest posts

D
Replies
0
Views
1
Danish Karmally
D
Top