使用angularJs 的 ngRoute 构建单页面应用时因为页面应用比较多想实现动态加载的功能,根据事件尽心路由配置
如果直接使用 绑定模块的配置方法可以获取对应页面数据,
// create the module and name it scotchApp
var scotchApp = angular.module('scotchApp', ['ngRoute']);
// configure our routes
scotchApp.config(function($routeProvider) {
$routeProvider.when('/', {
controller : 'myCtrl',
templateUrl : getUrl("wxappList"),
});
});
scotchApp.controller('mainController', function($scope) {
});
如果在控制器中声名方法就不会执行
var scotchApp = angular.module('scotchApp', ['ngRoute']);
// configure our routes
scotchApp.controller('mainController', function($scope) {
$scope.run = function(){
scotchApp.config(function($routeProvider) {
$routeProvider.when('/', {
controller : 'myCtrl',
templateUrl : getUrl("wxappList"),
});
});
}
$scope.run();
});
我们公司的老项目 也是用的 AngularJS
每个模块加载对应的js和css
我们使用的是Angular的第三方路由:ui-router
或者使用oclazyload也可以
参考:
https://www.cnblogs.com/pengj...
https://www.cnblogs.com/jonne...