简体   繁体   English

将数据加载到另一个文件中后,控制器中的AngularJS调用函数

[英]AngularJS Calling function in controller after data is loaded in another file

I have this function in app.js which connects to an api using promises. 我在app.js中具有此功能,该功能使用promise连接到api。 The app that is selected to be opened depends on the user ID. 选择要打开的应用程序取决于用户ID。

me.boot = function () {
me.getUserID().then(me.openAppFunction);
};

Also, I have this function in my Home.js controller 另外,我的Home.js控制器中有此功能

getObjectsFromApp();

This function needs to be executed after the application is loaded in the other file, but I have no idea how to do this. 在将应用程序加载到其他文件中之后,需要执行此功能,但是我不知道如何执行此操作。 This app.js file is not a service or a factory, it is just a file that is called when the application loads all the scripts with require.js. 这个app.js文件不是服务或工厂,它只是在应用程序使用require.js加载所有脚本时调用的文件。 The only thing this file does is select which app to open in the api, so that is why it is only called once. 该文件唯一要做的就是选择要在api中打开哪个应用,因此这就是为什么它仅被调用一次的原因。

An Event is probably what you are looking for... 一个Event可能就是您想要的...

You should stay in the angular environment, so, you should use $rootScope.$broadcast and $rootScope.$on and they can be used everywhere in your application because $rootScope is singletone. 您应该留在有角度的环境中,因此,应该使用$rootScope.$broadcast$rootScope.$on ,它们可以在应用程序中的任何地方使用,因为$rootScope是单调的。

this Why do we use $rootScope.$broadcast in AngularJS? 为什么我们在AngularJS中使用$ rootScope。$ broadcast? could help you. 可以帮助您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM