我有一个ASP.NET MVC和AngularJS的应用程序。
我的路线由AngularJS管理ui-router
。
AngularJS第一次加载部分视图时它比第二次更慢。是什么导致这个?
有我的代码:
AngularJS
app.config(function ($httpProvider, $urlRouterProvider, $locationProvider, $stateProvider) {
$urlRouterProvider.otherwise('/home');
$httpProvider.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
$locationProvider.html5Mode(true);
var homeState = {
name: 'home',
url:'/home',
controller: 'HomeCtrl',
controllerAs:'vm',
templateUrl:'/AngularJS/Home/Home' //AngularJS is a Area/Controler/Method
}
var loginState = {
name: 'login',
url: '/login',
controller: 'LoginCtrl',
controllerAs: 'vm',
templateUrl: '/AngularJS/Home/Login'
}
var registrationState = {
name: 'registration',
url: '/registration',
controller: 'RegistrationCtrl',
controllerAs: 'vm',
templateUrl: '/AngularJS/Home/Registration'
}
var dashboardState = {
name: 'dashboard',
url: '/dashboard',
controller: 'DashboardCtrl',
controllerAs: 'vm',
templateUrl: '/AngularJS/Home/Dashboard'
}
...
$stateProvider.state(homeState);
$stateProvider.state(loginState);
$stateProvider.state(registrationState);
$stateProvider.state(dashboardState);
$stateProvider.state(gameState);
$stateProvider.state(userState);
$stateProvider.state(newGameState);
$stateProvider.state(platformState);
$stateProvider.state(unavailabilityState);
$stateProvider.state(teamsState);
$stateProvider.state(newTeamState);
$stateProvider.state(editTeamState);
$stateProvider.state(detailTeamState);
$httpProvider.interceptors.push(requestInterceptor);
})
ASP.NET MVC
public PartialViewResult Home()
{
ViewBag.Title = "Home";
return PartialView();
}
public PartialViewResult Login()
{
ViewBag.Title = "Login";
return PartialView();
}
public PartialViewResult Registration()
{
ViewBag.Title = "Registration";
return PartialView();
}
public PartialViewResult Dashboard()
{
ViewBag.Title = "Dashboard";
return PartialView();
}
...