How to use ngSwitch in angular2

Also facing the same issue Make sure

  1. NgSwitch should not be no template it should be on real element like Div
  2. *ngSwitchCase="expression" should be nested inside NgSwitch element

You need to import ngSwitch from angular2/common

import {NgSwitch} from 'angular2/common'

https://angular.io/docs/ts/latest/api/common/index/NgSwitch-directive.html

ngSwitch can't be on a <template> element, only on real elements like <div>

Only ngSwitchCase can be applied to <template> elements

<template [ngSwitchCase]="match_expression_3">

Alternatively since final ng-container can be used instead of <template> with the more common syntax:

<ng-container *ngSwitchCase="match_expression_3">

Tags:

Angular