在启动角度应用程序时执行代码 [英] Execute code at startup of angular application
本文介绍了在启动角度应用程序时执行代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有一种方法可以在AngularJS应用程序启动时执行一些JavaScript代码?我有一些通用代码需要确保在任何应用程序指令/控制器之前运行.我不想被路由和ng-view
所束缚,我需要它成为任何ng-app
的通用解决方案.
Is there a way I can execute some JavaScript code at start-up of my AngularJS application? I have some common code that I need to make sure runs before any of the app directives/controllers. I do not want to be tied to routes and ng-view
, I need this to be a generic solution for any ng-app
.
我以为我可以使用Module Config,但实际上我曾尝试过,但是我正在尝试调用一项服务,该服务似乎无法在Module Load上访问.
I thought I could use Module Config, and I actually tried that, but I am trying to call a service, which seems impossible to access on Module Load.
推荐答案
您可以这样做,
var app = angular.module('myApp',[]);
app.run(function($rootScope) {
//.....
});
这篇关于在启动角度应用程序时执行代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文