0

I found the code:

var app = angular.module("app",[]);
  app.config(function($routeProvider){
      $routeProvider
      .when('/main',{
         templateUrl:"mainView.html",
         controller:mainController
       })
       .when('/anyName',{
         templateUrl:"templates/view3.html",
         controller:temp3Controller
       })
  });

What if I want to include the file in router stage by using just file for example? such as

var app = angular.module("app",[]);
  app.config(function($routeProvider){
      $routeProvider
      .when('/main',{
         templateUrl:"mainView.html",
         controller:mainController
         files: ["css/mainController.css", "js/mainController.js"]
       })
       ...
  });
Weijing Jay Lin
  • 2,991
  • 6
  • 33
  • 53
  • What are you trying to do? – Casey Sep 19 '16 at 22:50
  • @Casey I want to have a lazy load without add up all file into index.html file. – Weijing Jay Lin Sep 19 '16 at 22:53
  • @NilesTanner There are only one module, don't you think that it is single page app? – Weijing Jay Lin Sep 19 '16 at 22:59
  • @DotKu doing a bit of research it looks like the router isn't the right place to do this. I would look at this post: http://stackoverflow.com/questions/23656231/angularjs-dynamic-loading-of-external-js-based-on-routes – Niles Tanner Sep 19 '16 at 23:03
  • I wouldn't recommend doing this. The typical way to improve performance is to combine the files into one file at runtime and avoid the overhead of multiple requests. – Casey Sep 20 '16 at 01:19
  • @DotKu Could u please look into this url,might help u for lazy loading. http://stackoverflow.com/questions/19434249/angular-js-how-to-load-js-files-in-partials – Umakanta Behera Sep 20 '16 at 04:29

0 Answers0