为什么(click)=“ handleEdit()”在这里不起作用

时间:2019-04-30 17:03:26

标签: angular primeng

有人可以告诉我为什么(click)= handleEdit($ event)不起作用吗?我已经加粗了下面的HTML。它使用priming p按钮。我已经发布了类似的问题,但我认为这个问题更重要。

    <div class="ui-g-12 ui-md-10 ui-g-nopad">
        <div class="ui-g-12">
            <p-toolbar id="toolbarId">
                <div class="ui-toolbar-group-left">
                    **<button pButton type="button" label="Edit" icon="pi pi-search" id="editBtn" class="ui-button-danger" (click)="handleEdit($event)"></button>**                   
                </div>

                <div class="ui-toolbar-group-right">
                    <button pButton type="button" icon="pi pi-search" id="searchId"></button>
                    <button pButton type="button" icon="pi pi-calendar" class="ui-button-success"
                        id="calendarBtn"></button>
                    <button pButton type="button" icon="pi pi-times" class="ui-button-danger" id="exitBtn"></button>      
                </div>
            </p-toolbar>
        </div>
        <router-outlet></router-outlet>
     </div>



export class HomescreenComponent implements OnInit {
  title = 'niche-app Home';
  appMenu: AppMenu;

  constructor(private appMenuService: AppMenuService) { }

  items: MenuItem[];

  ngOnInit() {
    this.appMenu = this.appMenuService.getAppMenu();
    ...
  }

  handleEdit() {
    console.log("handleEdit(): Called...");
  }

}

2 个答案:

答案 0 :(得分:0)

<android.support.v7.widget.AppCompatButton
    android:id="@+id/button_login"
    ...
    app:onTouchListener="@{viewModel.onTouchListener}" />

请复制html到页面中,然后单击按钮。我已经测试并在控制台中打印了

答案 1 :(得分:0)

我发现了问题所在。路由器出口标签需要移动到p工具栏标签的正下方。将其放置在原位使其不是主屏幕父级组件的子级。

一旦我将路由器出口位置移到homescreen.html文件中,它就会开始响应(单击)事件。

感谢guptarahul275花时间回答我的问题。

    <div class="ui-g-12 ui-md-10 ui-g-nopad">
    <div class="ui-g-12">
        <p-toolbar id="toolbarId">
            <div class="ui-toolbar-group-left">
                <button pButton type="button" label="New" icon="pi pi-plus" id="newBtn"></button>
                <button pButton type="button" label="Edit" icon="pi pi-search" id="editBtn" class="ui-button-danger" (click)="handleEdit($event)"></button>
                <button pButton type="button" label="Upload" icon="pi pi-upload" class="ui-button-success"
                    id="uploadBtn"></button>

                <i class="pi pi-bars"></i>

                <p-splitButton label="Save" icon="pi pi-check" [model]="items" styleClass="ui-button-warning"
                    id="saveBtn"></p-splitButton>
            </div>

            <div class="ui-toolbar-group-right">
                <button pButton type="button" icon="pi pi-search" id="searchId"></button>
                <button pButton type="button" icon="pi pi-calendar" class="ui-button-success"
                    id="calendarBtn"></button>
                <button pButton type="button" icon="pi pi-times" class="ui-button-danger" id="exitBtn"></button>
            </div>
        </p-toolbar>
        <router-outlet></router-outlet>
    </div>
    **router-outlet used to be here**
</div>