Menubar Problem

UI Components for Angular
Post Reply
zho
Posts: 2
Joined: 11 Oct 2014, 11:29

23 Jun 2016, 10:02

I'm Trying to make a menubar using PrimeNG, based on example from http://www.primefaces.org/primeng/#/menubar

i create something like this:

app.component.ts

Code: Select all

import {Component} from '@angular/core';

import { MenubarDemo } from "./menubardemo.component";

@Component({
  selector: 'my-app',
  template: '<h1>My First Angular 2 App</h1><p-menubar [model]="items"></p-menubar>'
})

export class AppComponent {
  items = new MenubarDemo();
}
menubardemo.components.ts

Code: Select all

import {MenuItem} from "primeng/primeng";

export class MenubarDemo {

  private items: MenuItem[];

  ngOnInit() {
    this.items = [
      {
        label: 'File',
        icon: 'fa-file-o',
        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'}
        ]
      },
      {
        label: 'Help',
        icon: 'fa-question',
        items: [
          {
            label: 'Contents'
          },
          {
            label: 'Search',
            icon: 'fa-search',
            items: [
              {
                label: 'Text',
                items: [
                  {
                    label: 'Workspace'
                  }
                ]
              },
              {
                label: 'File'
              }
            ]}
        ]
      },
      {
        label: 'Actions',
        icon: 'fa-gear',
        items: [
          {
            label: 'Edit',
            icon: 'fa-refresh',
            items: [
              {label: 'Save', icon: 'fa-save'},
              {label: 'Update', icon: 'fa-save'},
            ]
          },
          {
            label: 'Other',
            icon: 'fa-phone',
            items: [
              {label: 'Delete', icon: 'fa-minus'}
            ]
          }
        ]
      },
      {
        label: 'Quit', icon: 'fa-minus'
      }
    ];
  }
}
after i checked out the data object is printed on the DOM, but the menubar not showing.

Image

maipucino
Posts: 112
Joined: 19 Apr 2010, 22:04

24 Jun 2016, 01:38

items should be an array of menuitems. When you say " items = new MenubarDemo();" you are assigning an MenubarDemo object to "items" instead of contained items array. it should be somethng like

Code: Select all

items = new MenubarDemo().items 
after making items public.

zho
Posts: 2
Joined: 11 Oct 2014, 11:29

25 Jun 2016, 09:25

maipucino wrote:items should be an array of menuitems. When you say " items = new MenubarDemo();" you are assigning an MenubarDemo object to "items" instead of contained items array. it should be somethng like

Code: Select all

items = new MenubarDemo().items 
after making items public.
Not working, so? what should it printed? in model? in html?

Post Reply

Return to “PrimeNG”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 20 guests