使用AngularJS从index.html / appController.js调用控制器的函数

时间:2018-03-30 11:19:33

标签: javascript angularjs

我有一个应用程序,其中导航,页眉,页脚等直接进入index.html。问题是在导航中有一个名为通知的选项卡,我有一个新的要求,它应该包含通知的数量。例如:

<ul id="navigation">
    <li>
        <a data-ui-sref="allNotifications">Notifications {{amount}}</a>
    </li>
</ul>

我需要的功能在allNotificationsController.js

$scope.getNotifications = function() {
    ...
    return notifications; //returns array
}

最简单的方法是DOM编辑数组的长度,但只有当我在属于控制器的页面时才会发生。我希望通知始终可见。有没有办法直接从index.html或根控制器(app.controller.js)调用该函数而不重写所有逻辑?

0 个答案:

没有答案