gpt4 book ai didi

javascript - 在每个 Controller 的开头运行一个函数

转载 作者:行者123 更新时间:2023-12-02 16:13:43 24 4
gpt4 key购买 nike

我想在我拥有的每个 Controller 的开头运行一个函数,如下所示:

faraWorkspaceApp.controller('AccountController', function () {
FaraFunctions(); // this function
});

faraWorkspaceApp.controller('DashboardController', function () {
FaraFunctions(); // this function
});

faraWorkspaceApp.controller('ChangePasswordController', function () {
FaraFunctions(); // this function
});

如何放置此代码并防止在 Angular js 中重复 FaraFunctions(); 代码?

最佳答案

我发现的最好方法是$viewContentLoaded:

faraWorkspaceApp.run(function ($rootScope, $location, $state, $templateCache) {
$rootScope.$on('$viewContentLoaded', function (e) {
FaraFunctions();
});
});

关于javascript - 在每个 Controller 的开头运行一个函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29892919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com