如何使用导航器按钮执行页面之间导航以外的操作

How to use navigator buttons to execute actions other than navigate between pages

本文关键字:导航 之间 操作 何使用 按钮 执行      更新时间:2023-09-26

假设我有以下使用Onsenui的应用程序片段:

<ons-navigator-toolbar title=""
    left-button-icon="fa fa-lg fa-edit"
    on-left-button-click="window.alert('asdf');"
    right-button-icon="fa fa-lg fa-plus"
    on-right-button-click="myAngularFunction();">
</ons-navigator-toolbar>

事件on-left-button-clickon-right-button-click的函数没有被调用。只是在页面之间导航的功能(例如,ons.screen.presentPage('other_page.html'))。

这是一个已知的Onsenui限制,一个设计原则还是一个bug?有什么办法克服它吗?

这是AngularJS的限制。

您不能在AngularJS之外调用函数。

您可以将window.alert函数封装在控制器函数中。

此外,您需要将控制器设置在ons导航器之上。

如果使用,ons导航器工具栏,其作用域不是页面,而是导航器作用域。这是Onsen UI的当前限制,正在下一个版本中解决。