1
I am starting my studies in Angular 7 and in a class on Structural Directives, I learned that I can add or remove elements HTML of DOM.
I understood that there are 3 main, the ngIf, the ngSwitch and the ngFor.
The ngIf and the ngSwitch are used to conditionally rederizate the elements HTML.
The ngFor is used to render a list of elements HTML.
Using the 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 in the same file.
When ngIf is set to true, on the screen looks like this:
And when it’s set to false, gets like this:
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?


in dynamic elements, think of a stock control where it can be controlled by und. or weight by item feature vc can apply dynamicity if it is of type und, has such control or even such input, or if it is weight such control or such input
– Willian