2017-05-31 51 views
0

我嘗試PrimeNG在我的項目angular4整合,我跟着網站的設置,但是當我導入一個模塊,它會顯示錯誤消息,例如:Angular4:PrimeNG不行

Can't bind to 'ngModel' since it isn't a known property of 'p-inputSwitch'. 

home.module。 TS

import { NgModule } from '@angular/core'; 
import { ChartsModule } from 'ng2-charts/ng2-charts'; 
import { BsDropdownModule } from 'ngx-bootstrap/dropdown'; 

import { HomeComponent } from './home.component'; 
import { HomeRoutingModule } from './home-routing.module'; 
import {InputSwitchModule} from 'primeng/primeng'; 

@NgModule({ 
    imports: [ 
    HomeRoutingModule, 
    ChartsModule, 
    BsDropdownModule, 
    InputSwitchModule 
    ], 
    declarations: [ HomeComponent ] 
}) 
export class HomeModule { } 

home.component.ts

import { Component, OnInit } from '@angular/core'; 
import { Router } from '@angular/router'; 

@Component({ 
    templateUrl: 'home.component.html' 
}) 
export class HomeComponent implements OnInit { 

    // constructor() { } 
    checked1: boolean = false; 
    checked2: boolean = true; 
/
. 
. 
. 
/
} 

home.component.html

<h3 class="first">Basic - {{checked1}}</h3> 
<p-inputSwitch [(ngModel)]="checked1"></p-inputSwitch> 

<h3>Labels - <span> {{checked2}}</span></h3> 
<p-inputSwitch onLabel="Yes" offLabel="No" [(ngModel)]="checked2"></p-inputSwitch> 
+0

您是否爲ngModel導入FormModule? – Val

+0

感謝您的回答,我不得不將FormModule導入到全局模塊中,並且當我將FormModule導入到home.module.ts時,它的工作原理是 – Anas

回答

2

如果您未導入「FormModule」,您將看到此消息。 對於你的情況,我沒有看到這個地方。

Can't bind to 'ngModel' since it isn't a known property of X. 

此消息表明無法找到'ngModel'聲明。

+0

非常感謝你的工作 – Anas