We can change the view in the Angularjs according to the URL, dynamically load the page template, but the control template controller needs to be defined before you can, and the page template at the same time to load, so that the entire site of JS must be loaded first.
requirejs is the first thing we think of, but the volume is a bit big, on GitHub on the individual with it wrote the angular dynamic load controller module, is through JS Promise asynchronous programming technology, The Final solution is simple ~ ~
First add resolve property in $routeprovider,
$routeProvider. When ('/phones ', { templateurl: ' partials/phone-list.html ', Controller:phonelistctrl, resolve: Phonelistctrl.resolve})
And then
function Phonelistctrl ($scope) { ///itself without tube, how to get}phonelistctrl.resolve = { delay:function ($q) { var Delay = $q. Defer (), load = function () { $.getscript ('/js/xxxxx.js ', function () { delay.resolve (); }); }; load (); return delay.promise;} }
With this technology, our Hybridapp can be divided into static packaging in the native application of the part, and placed on the server dynamic part, easy to upgrade the main app without the premise of adding some temporary page function. Specific application scenarios Let's think for yourself!