2017-03-10 3 views
3

다음과 같은 오류가 나타납니다. 'ngSwitchWhen'은 '템플릿'의 알려진 속성이 아니기 때문에 바인딩 할 수 없습니다. ' 나는Angular2 - "ngSwitchWhen '은'템플릿 '의 알려진 속성이 아니기 때문에 바인딩 할 수 없습니다."

'각도/공통 @'가에서

수입 {CommonModule}을 추가 할 것을 권고 한 다른 주제를 읽고 @NgModel의 수입 섹션에 "CommonModule"를 추가했습니다되는 I 그렇지만 이것은 문제를 해결하지 못했습니다. 내가 뭘 잘못하고 있는지,이 문제를 해결하는 방법에 대한 도움을 알아낼 수 없습니까?

이 내 코드는 "app.component.ts"

import { Component } from '@angular/core' 

@Component({ 
    selector: 'app-root', 
    template: ` 
    <ul class="nav nav-pills"> 
     <li [class.active]="viewMode == 'map'"><a (click)="viewMode = 'map'">Map View</a></li> 
     <li [class.active]="viewMode == 'list'"><a (click)="viewMode = 'list'">List View</a></li> 
    </ul> 
    <div [ngSwitch]="viewMode"> 
    <template [ngSwitchWhen]="'map'" ngSwitchDefault>Map View Content></template> 
    <template [ngSwitchWhen]="'list'">List View Content</template> 
    </div> 
    ` 
}) 

export class AppComponent { 
    viewMode = 'map'; 
} 

그리고이 그것은 ngSwitchCase 대신 ngSwitchWhen해야한다 "app.module.ts"

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 { 

} 

답변