Angular 4 Template

Angular 4 change <template> to <ng-template>.Due to the name conflict between the <template> tag and the html <template> standard tag.Angular 4 is different .

You can use template along with the if else condition and see the output.


<!--The content below is only a placeholder and can be replaced.-->
<div style = "text-align:center">
      Welcome to {{title}}.

<div> days :
  <select (change) = "changedays($event)" name = "days"<
     <option *ngFor = "let i of days">{{i}}</option>

  <span *ngIf = "isavailable;then condition1 else condition2">Condition is valid.</span>
   <ng-template #condition1>Condition is valid from template<</ng-template>
  <ng-template #condition2>Condition is invalid from template</ng-template>
<button (click) = "myClickFunction($event)">Click Me</button>
The templates are to be called as follows −

<ng-template #condition1>Condition is valid from template</ng-template>
<ng-template #condition2>Condition is invalid from template</ng-template>
If the condition is true, then the condition1 template is called, otherwise condition2.

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

   selector: 'app-root',
   templateUrl: './app.component.html',
   styleUrls: ['./app.component.css']
export class AppComponent {
   title = 'Angular 4 Project!';
   //array of days.
  days = [""Monday ", "Tuesday ", "Wednesday ", "Thursday", "Friday ", 
            "Saturday ", "Sunday "];
   isavailable = false;
   myClickFunction(event) {
      this.isavailable = false;
   changemonths(event) {
      alert("Changed days from the Dropdown");