2017-09-26 71 views
0

我收到以下錯誤消息。它告訴我,它不能綁定'模型',因爲它不被'p-menubar'所知。primeng p-menubar示例不起作用

我是非常新的角度和primeng。有人能幫我嗎?

Error: Template parse errors: Can't bind to 'model' since it isn't a known property of 'p-menubar'. 1. If 'p-menubar' is an Angular component and it has 'model' input, then verify that it is part of this module. 2. If 'p-menubar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. 3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. (" ][model]="items"> "): ng:///AppModule/[email protected]:23 'p-menubar' is not a known element: 1. If 'p-menubar' is an Angular component, then verify that it is part of this module. 2. If 'p-menubar' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (" [ERROR ->] "): ng:///AppModule/[email protected]:12 Evaluating http://localhost:3000/main.js Loading main.js Stack trace: [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1729:34 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:12967:19 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27161:18 JitCompiler.prototype._compileComponents/<@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27080:56 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:27080:9 JitCompiler.prototype._compileModuleAndComponents/<@http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:26967:13 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:1718:92 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:26966:16 [email protected]http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:26895:32 [email protected]http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4568:16 [email protected]http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:4554:16 @http://localhost:3000/main.js:4:1 @http://localhost:3000/main.js:1:31 @http://localhost:3000/main.js:1:2 [email protected]http://localhost:3000/node_modules/systemjs/dist/system.src.js:2843:8 translateAndInstantiate/http://localhost:3000/node_modules/systemjs/dist/system.src.js:3608:21 [email protected]http://localhost:3000/node_modules/systemjs/dist/system.src.js:1166:18 [email protected]http://localhost:3000/node_modules/systemjs/dist/system.src.js:1113:13 [email protected]http://localhost:3000/node_modules/systemjs/dist/system.src.js:1022:13 RegisterLoader$1.prototype[Loader.resolveInstantiate]/http://localhost:3000/node_modules/systemjs/dist/system.src.js:612:14 [email protected]http://localhost:3000/node_modules/zone.js/dist/zone.js:392:17 [email protected]http://localhost:3000/node_modules/zone.js/dist/zone.js:142:24 scheduleResolveOrReject/<@http://localhost:3000/node_modules/zone.js/dist/zone.js:844:52 [email protected]http://localhost:3000/node_modules/zone.js/dist/zone.js:425:17 [email protected]http://localhost:3000/node_modules/zone.js/dist/zone.js:192:28 [email protected]http://localhost:3000/node_modules/zone.js/dist/zone.js:602:25 k/http://localhost:3000/node_modules/core-js/client/shim.min.js:8:31581 k/<@http://localhost:3000/node_modules/core-js/client/shim.min.js:8:31451 [email protected]http://localhost:3000/node_modules/core-js/client/shim.min.js:7:25990 localhost:3000:22:53

這是app.component.ts代碼:

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

@Component({ 
    selector: 'my-app', 
    template: ` 
      <p-menubar [model]="items"> 
       <input type="text" pInputText placeholder="Search"> 
       <button pButton label="Logout" icon="fa-sign-out"></button> 
      </p-menubar> 
    ` 
// templateUrl: './app/app.component.html' 
}) 
export class AppComponent { 

    items: MenuItem[]; 

    ngOnInit() { 
     this.items = [ 
      { 
       label: 'File', 
       items: [{ 
         label: 'New', 
         icon: 'fa-plus', 
         items: [ 
          {label: 'Project'}, 
          {label: 'Other'}, 
         ] 
        }, 
        {label: 'Open'}, 
        {label: 'Quit'} 
       ] 
      }, 
      { 
       label: 'Edit', 
       icon: 'fa-edit', 
       items: [ 
        {label: 'Undo', icon: 'fa-mail-forward'}, 
        {label: 'Redo', icon: 'fa-mail-reply'} 
       ] 
      } 
     ]; 
    } 
} 

這是app.module.ts:

import { NgModule }  from '@angular/core'; 
import { BrowserModule } from '@angular/platform-browser'; 
import { AppComponent } from './app.component'; 

@NgModule({ 
    imports:  [ BrowserModule], 
    declarations: [ AppComponent ], 
    bootstrap: [ AppComponent ] 
}) 
export class AppModule { } 

回答

1

我發現這個問題。 「從primeng/primeng'導入{MenubarModule,MenuItem};」需要在app.module.ts中,而不是在app.component.ts中。