javascript - Why are global variables defined in .run() of app.js in Ionic, which can be accessed in the controller of the page, but cannot be accessed after refreshing?
怪我咯
怪我咯 2017-06-12 09:22:30
0
1
747

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?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(1)
左手右手慢动作

The execution sequence of angular.js is roughly as follows:

  1. app.config()

  2. app.run()

  3. Instructions to compile

  4. app.controller()

  5. Command link

It’s difficult to judge your problem. I guess it may be because of the loading order of your .js.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template