Why would it be nice to add or remove HTML elements from the DOM?

1

I'm starting my studies in Angular 7 and in a lesson on Structural Directives, I learned that I can add or remove elements HTML of DOM .

I understand that there are 3 main , ngIf , ngSwitch and ngFor .

The ngIf and ngSwitch are used to conditionally rotate the HTML elements. ngFor is used to render a list of HTML elements.

Using ngIf , I have an example:

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-test',
  //templateUrl: './test.component.html',
  template: '

    <h2 *ngIf="true">
        Marcielli
    </h2>
  ',
  styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

NOTE: For study purpose, I am using the same file.

When ngIf is set to true , the screen looks like this:

Andwhensettofalse,itlookslikethis:

The question is: In what real situation would I use this? For what reason, for example, would I want to remove an element from the DOM?

    
asked by anonymous 24.11.2018 / 18:32

0 answers