2017-05-06 70 views
0

嘗試primeng學習,我修改了cli生成的起始代碼如下。步驟菜單不顯示在Primeng

app.component.ts

import { Component } from '@angular/core'; 
import {StepsModule,MenuItem} from 'primeng/primeng'; 

@Component({ 
    selector: 'app-root', 
    templateUrl: './app.component.html', 
    styleUrls: ['./app.component.css'] 
}) 
export class AppComponent { 

    name: string; 

    message1: string; 

    private items: MenuItem[]; 

    ngOnInit() { 
     this.items = [ 
      {label: 'Step 1'}, 
      {label: 'Step 2'}, 
      {label: 'Step 3'} 
     ]; 
    } 

    onClick() { 
     this.message1 = 'Hello ' + this.name; 
    } 
} 

app.component.html從而:

<input type="text" [(ngModel)]="name" pInputText> 
<button type="button" pButton label="Click" icon="fa fa-check" (click)="onClick($event)"></button> 

<div>{{message1}}</div> 
<p-fileUpload name="myfile[]" url="http://localhost/"></p-fileUpload> 


<p-steps [model]="items" [readonly]="false"></p-steps> 

app.module.ts從而:

import { BrowserModule } from '@angular/platform-browser'; 
import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 
import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { HttpModule } from '@angular/http'; 
import { InputTextModule, ButtonModule } from 'primeng/primeng'; 
import {FileUploadModule} from 'primeng/primeng'; 
import {StepsModule,MenuItem} from 'primeng/primeng'; 

import { AppComponent } from './app.component'; 

@NgModule({ 
    declarations: [ 
    AppComponent 
    ], 
    imports: [ 
    BrowserModule, 
    BrowserAnimationsModule, 
    FormsModule, 
    HttpModule, 
    InputTextModule, 
    ButtonModule, 
    FileUploadModule, 
    StepsModule 
    ], 
    providers: [], 
    bootstrap: [AppComponent] 
}) 
export class AppModule { } 

它顯示此幾乎空白屏幕沒有控制檯錯誤:

enter image description here

當我刪除了P-步驟標籤,它顯示了其他元素正確

enter image description here

什麼我收到錯誤關於P-步驟?

+0

你會得到任何控制檯錯誤? – Aravind

+0

沒有任何。 – user1729972

回答

0

嘗試從進口中刪除'MenuItem'。當我在app.module.ts中添加MenuItem時,出現編譯錯誤。

錯誤:'MenuItem'只引用一個類型,但在此處被用作值。

只在組件中導入它應該工作。