android - Ionic/AngularJS 菜单栏刷新按钮到当前 View Controller

标签 android ios angularjs ionic-framework

我们正在使用 AngularJS 构建一个 Ionic 应用程序。该应用程序在屏幕顶部有一个菜单栏,其中有一个用于打开侧面/汉堡菜单的按钮和一个刷新按钮。

菜单位于单独的 HTML 文件中,并且有自己的 Controller ,可以使当前菜单项处于 Activity 状态。

在 app.js 中,状态是为哪个 View 具有哪个 Controller 而定义的。

菜单栏的右上角有一个刷新按钮,但是如何使该按钮(与菜单具有相同的 Controller )调用当前 View Controller 范围内的函数?

最佳答案

您可以通过 events 完成此操作.

链接到 Controller A 的模板:

...
<a href="#" ng-click="refresh()">Refresh</a>
...

Controller A:

.controller('AppCtrl', function($scope, $rootScope) {

    $scope.refresh = function() {
        // Your refresh code
        $rootScope.$emit('refreshedPressed');
    }

}

Controller B:

.controller('OtherCtrl', function($scope, $rootScope) {

   $rootScope.$on('refreshedPressed', function() {
       // Handle the event.
   });

}

关于android - Ionic/AngularJS 菜单栏刷新按钮到当前 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29773288/

相关文章:

java - Android 中的基本身份验证登录

android - 如何在 react-native 中更改应用程序的显示名称

iphone - iOS 在 iOS 6 中隐藏标签栏会创建黑条(针对 iOS 6 的修复破坏了 iOS 7!)

javascript - AngularJs 1.x 无法与 SemanticUI.js 一起使用

javascript - 如何使用 Angular JS 将数据从 json 转换为对象列表

android - {"error": {"message" :"(#324) Requires upload file" ,"type" :"OAuthException" ,"code":324}}

android - 覆盖静音模式和/或媒体音量

ios - 从 Firebafirebase 崩溃报告 OLD 迁移到 Firebase/Crashlytics

ios - 带有委托(delegate)引用的 Swift 默认参数值

javascript - 如何使用 HTML5 和 Raphael JS 构建图像编辑器?