Emilio Numazaki
Emilio Numazaki

Reputation: 892

*ngIf and child components

I'm trying to create a component that has a parameter that defines if some part of template will be rendered. Here is my child component:

Render below? {{render}}
<p *ngIf="render">
    Content to be rendered
</p>

And this is the usage in main component:

<app-test render="false"></app-test>

Finally, this is the code:

export class TestComponent implements OnInit {

  @Input() render: boolean = true;

  constructor() { }

  ngOnInit() {
  }

}

This is the result:

enter image description here

Please note that "render" attribute is "false" but the part of code that should be rendered based on parameter is still rendered.

Here is the StackBlitz: https://stackblitz.com/edit/angular-zch3gp

Thanks in advance

Upvotes: 1

Views: 399

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71971

You should use binding brackets, now you are just binding the string 'false':

<app-test [render]="false"></app-test>

Upvotes: 10

Related Questions