angular.js - How to load gracefully on demand in angularjs
漂亮男人
漂亮男人 2017-05-15 16:54:04
0
2
531

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?

漂亮男人
漂亮男人

reply all(2)
淡淡烟草味

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

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