Requirements:
One of my applications has two controllers, controllerA and controllerB. The initial page entered by the application is a.html controlled by controllerA. When the user enters B from A, the Amap map must be loaded in b.html.
The current approach is to load the Amap JS library in the index.html file, which can be called in both controllers, but this has disadvantages
1. Slow down application loading speed
2. Many users open the application just for a.html and will not continue to click to go to b.html
I hope:
Load the Amap js library in controllerB. I will load it only if the user needs it
How do you do it?
I think the problem you need to solve is how to dynamically load
高德地图API
,只要解决了这个问题,angular-route
中$routeProvider
自带的resolve
, and your problem can be solved.Look at my Plunker
https://github.com/marcoslin/angularAMD