title: Angular2 - "Can't bind to 'ngSwitchWhen' since it isn't a known property of 'template'."
body: <p>I am getting the following error "Can't bind to 'ngSwitchWhen' since it isn't a known property of 'template'." I've read different topics where it was advised to add </p>
  
  <blockquote>
    <p>import { CommonModule } from '@angular/common'</p>
  </blockquote>
  
  <p>and add "CommonModule" into the imports section of @NgModel, which I did, however this did not solve the problem. I can't figure out what I'm doing wrong, any help in how to fix this?</p>
  
  <p>This is my code for "app.component.ts"</p>
  
  <pre><code>import { Component } from '@angular/core'
  
  @Component({
    selector: 'app-root',
    template: `
       &lt;ul class="nav nav-pills"&gt;
          &lt;li [class.active]="viewMode == 'map'"&gt;&lt;a (click)="viewMode = 'map'"&gt;Map View&lt;/a&gt;&lt;/li&gt;
          &lt;li [class.active]="viewMode == 'list'"&gt;&lt;a (click)="viewMode = 'list'"&gt;List View&lt;/a&gt;&lt;/li&gt;
       &lt;/ul&gt;
       &lt;div [ngSwitch]="viewMode"&gt;
       &lt;template [ngSwitchWhen]="'map'" ngSwitchDefault&gt;Map View Content&gt;&lt;/template&gt;
       &lt;template [ngSwitchWhen]="'list'"&gt;List View Content&lt;/template&gt;
       &lt;/div&gt;
      `
  })
  
  export class AppComponent {
    viewMode = 'map';
  } 
  </code></pre>
  
  <p>And this is the code for "app.module.ts"</p>
  
  <pre><code>import { BrowserModule } from '@angular/platform-browser';
  import { NgModule, ApplicationRef } from '@angular/core';
  import { FormsModule } from '@angular/forms';
  import { HttpModule } from '@angular/http';
  import { CommonModule } from '@angular/common';
  
  import { AppComponent } from './app.component';
  import { FavoriteComponent } from './favorite.component';
  import { HeartComponent } from './heart.component';
  import { VoteComponent } from './vote.component';
  import { TweetComponent } from './tweet.component';
  
  @NgModule({
    declarations: [
      AppComponent,
      FavoriteComponent,
      HeartComponent,
      VoteComponent,
      TweetComponent
    ],
    imports: [
      BrowserModule,
      FormsModule,
      HttpModule,
      CommonModule
    ],
    providers: [],
    entryComponents: [AppComponent],
    bootstrap: [AppComponent]
  })
  
  export class AppModule {
  
  }
  </code></pre>