0

I would like to display different lists (defined by a component), but display their headers only if a necessary Output is produced by the child component.

Say I have a component that, among other things, @Outputs an event, like so

export class ItemListComponent implements OnInit {

  @Input()
  private filter: (t: Item) => boolean;

  private tasks: TaskItem[];

  @Output()
  isEmpty = new EventEmitter();

In my other component I display this list, by injecting a necessary filter, like so

<div> list header  <-- I would love to hide that -->
<app-item-list [filter]="filter" *ngIf="!(isEmpty)">
</app-item-list>
</div>

I can hide the item list depending on the (isEmpty), but can I hide the div above?

2
  • when you want to hide the div ? Commented Apr 4, 2019 at 11:25
  • Please reproduce the issue on stackblitz. It helps contributors to help you. Commented Apr 4, 2019 at 11:28

2 Answers 2

2

You can use a variable in .parent.ts to hide and show your div

item-list.component.ts

export class ItemListComponent implements OnInit {

  @Input()
  private filter: (t: Item) => boolean;

  private tasks: TaskItem[];

  @Output()
  isEmpty = new EventEmitter(Boolean);

.parent.html

<div *ngIf="isShow"> list header  <-- I would love to hide that -->
<app-item-list [filter]="filter" *ngIf="!(isEmpty)" (isEmpty)="myFunc(e)">
</app-item-list>
</div>

.parent.ts

isShow = true;

myFunc(e){
  this.isShow = e;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of using 'div' you can use 'ng-container'.

<ng-container*ngIf="isShow"> list header  <-- I would love to hide that -->
<app-item-list [filter]="filter" *ngIf="!(isEmpty)" (isEmpty)="myFunc(e)">
</app-item-list>
</ng-container>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.