Use $rootScope.obj1 = {} to predefine global variables in the .run() function of app.js. When you start the program for the first time, you can access $rootScope in the .controller() function of the page. .obj1's. However, after refreshing the page on the browser, $rootScope.obj1 accessed in the .controller() function of the page becomes undefined.
I initially thought that the .run() function of app.js was not executed when refreshing, but after testing, it was found that it was executed. But the order of execution when refreshing seems to be: first execute the .controller() function of the page, then execute the .config() function in app.js, and then execute the .run() function in app.js. It's different from when you first start the program. Because of this sequence relationship, after refreshing the page, the predefined global variables cannot be accessed in the .controller() function of the page.
Excuse me, is this indeed the case? If so, how to solve this problem? Where should the predefined global variables be placed?
The execution sequence of angular.js is roughly as follows:
app.config()
app.run()
Instructions to compile
app.controller()
Command link
It’s difficult to judge your problem. I guess it may be because of the loading order of your .js.