weixin_33717298 2016-01-12 22:18 采纳率: 0%
浏览 147

AngularJs动态加载页面

How can i make a dynamic ajax load page function?

i don't want to declare all the 'routes' like this

angular.module('myApp', ['ngRoute'])
.config(function($routeProvider) {
  $routeProvider
    .when('/', {
      templateUrl: 'views/main.html',
      controller: 'MainCtrl'
    })
    .when('/day/:id', {
      templateUrl: 'views/day.html',
      controller: 'DayCtrl'
    })
    .otherwise({
      redirectTo: '/'
    });
})

i want to be able to load files with 1 function that does something like this;

<a href="myLinkToFile" ng-click="loadPage()">
loadPage function(){
 var url = "get the HREF of the element that is clicked"
 load the file and put it in a div
 and prevent default click of the <a>

}
  • 写回答

2条回答 默认 最新

  • weixin_33697898 2016-01-13 04:30
    关注

    In Angular, you have to declare all your routes before init app. I think your desire is to prevent load many resource files in the first init. If I get your thought, you can try ocLazyModule to optimize the load file performance

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器