What is the end goal here? When or how happens this "each time"? ng-template
is never generated in html code, it generates it's contents as html at run time. So adding new html lines to a template is not possible. It is a dynamic abstraction of Angular syntax.
However you could use template variables to pre-configure the template to add new lines when themplate bound variables change.
For example, you could add more template variables by adding let
to ng-template
. https://angular.io/guide/template-reference-variables#template-input-variable
<div *ngFor="let day of Weekdays">
<ng-container *ngIf =
"(day == 'Saturday' || day == 'Sunday'); else elseTemplate">
<h1>{{day}} is a weekend</h1>
</ng-container>
<ng-template #elseTemplate>
<h1>{{day}} is not a weekend</h1>
</ng-template>
</div>
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
name = 'Angular 6';
Weekdays: Array = [
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
];
}
Example: https://stackblitz.com/edit/hello-angular-6-ng-template-and-ng-container-exam-w2zn1j?file=src%2Fapp%2Fapp.component.html