p菜单未显示 [英] p-menu not showing up

查看:80
本文介绍了p菜单未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在测试带有角度2的primeng,并且想要创建一个简单的菜单.

I'm currently testing primeng with angular 2 and I want to create a simple menu.

这是我的代码:

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

@Component({
    templateUrl: 'app/salaries/menudroite.html',
    selector: 'menu-droite',
    providers: [],
   directives: [Menu]
})
export class menuDroiteComponent implements OnInit   {

  private items: MenuItem[];

  ngOnInit() {
        this.items = [{
        label: 'File',
        items: [
            {label: 'New', icon: 'fa-plus'},
            {label: 'Open', icon: 'fa-download'}
        ]
    },
    {
        label: 'Edit',
        items: [
            {label: 'Undo', icon: 'fa-refresh'},
            {label: 'Redo', icon: 'fa-repeat'}
        ]
    }];
  }

}

和html代码

<h4>Menu droite</h4>
<p-menu [model]="items"></p-menu>

当我启动网站时,什么都没有显示.如果删除html中的"p-menu"行,则会看到"h4" ...

When I launch the website nothing shows up. If I remove the "p-menu" line in the html, I see the "h4" ...

我在做什么错了?

推荐答案

因此我的作品与

<p-menu #menu popup="popup" [model]="items"></p-menu>

然后ts文件如下所示,只需查看导入和onInit

and then the ts file is as follows just look at the imports and the onInit

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

import { ServiceLocatorService } from '../../commonComponents/service/serviceLocator.service';

@Component({
    selector: 'productAdmin',
    template: require('./app.component.html'),
    styles: [require('./app.component.css')]
})
export class AppComponent {

    items: MenuItem[];

    constructor(private locator: ServiceLocatorService) {
        var url: string = location.origin;
        this.locator.setUrl(url);
    }

    ngOnInit() {
        this.items = [
            { label: 'Product Definition', routerLink: ['/productSetup']},
            { label: 'Base Product Pricing', routerLink: ['/productPricing'] },
            { label: 'Base Option Pricing', routerLink: ['/optionPricing']}
            ];
    }
}

这篇关于p菜单未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆