gpt4 book ai didi

angularjs - Angular - 应用启动事件

转载 作者:行者123 更新时间:2023-12-03 11:23:34 25 4
gpt4 key购买 nike

处理应用启动事件的最佳方式是什么?

我想在应用启动或应用刷新后自动登录用户。

我的代码放在哪里?

最佳答案

您想要在应用启动(或应用刷新)时运行的任何代码都应该放在 module.run() 中。您可以注入(inject)和使用诸如 http 之类的依赖项或其他服务,就像在 Controller 中一样。例如:

var app = ng.module('app', [/* top-level dependencies, modules */]);

app.run(['$http', '$q', function ($http, $q) {

// any code you want to run on app start/refresh, using any dependencies you've injected

}]);

关于angularjs - Angular - 应用启动事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19978301/

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