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

    评论

报告相同问题?