Javascript 首次加载角度视图故障

Javascript 首次加载角度视图故障,javascript,angularjs,Javascript,Angularjs,当用户单击超链接,我更改ng视图时,第一次需要更多的时间,但下一次以后,从一个视图到另一个视图的切换是平稳的,没有任何延迟。 我在这里收集了一个样品: 该plunker中的app.js看起来像: var sampleApp = angular.module('sampleApp', [ 'ngRoute', 'ngAnimate' ]); sampleApp.config(['$routeProvider', function($routeProvider) { $rout

当用户单击超链接,我更改ng视图时,第一次需要更多的时间,但下一次以后,从一个视图到另一个视图的切换是平稳的,没有任何延迟。 我在这里收集了一个样品:

该plunker中的app.js看起来像:

var sampleApp = angular.module('sampleApp', [
  'ngRoute',
  'ngAnimate'
]);

sampleApp.config(['$routeProvider',
  function($routeProvider) {
    $routeProvider.
    when('/ShowOrder/:orderId', {
      templateUrl: 'templates/show_order.html',
      controller: 'ShowOrderController'
    });
  }
]);


sampleApp.controller('ShowOrderController', function($scope, $routeParams) {


  $scope.order_id = $routeParams.orderId;
});

sampleApp.animation('.content',
  function() {
    return {
      enter: function(element, done) {
        var delay = $('.content').length === 2 ? 600 : 0; // if there are 2 .content (ngView) delay entrance, so the 1st can leave
        $(element).css({
          opacity: 0 // set the stage
        });
        $(element).delay(delay).animate({ // animate the opacity with delay if needed
          opacity: 1
        }, 600, done);
      },
      leave: function(element, done) {

        $(element).css({
          position: 'absolute', // use position absolute so the element won't jump down
          opacity: 1 // set the stage
        });
        $(element).animate({
          opacity: 0
        }, 600, done);

      }
    }
  }
)
在我的企业应用程序中,由于我做了更多的数据和变量初始化,用户更容易看到初始延迟


有没有办法让它更平滑?

初始延迟是由路由模板请求引起的。它可以通过提前缓存模板来消除

sampleApp.run(function ($http, $templateCache) {
  $http.get('templates/show_order.html', { cache: $templateCache });
});

或者在构建阶段通过或连接模板。

初始延迟由路由模板请求引起。它可以通过提前缓存模板来消除

sampleApp.run(function ($http, $templateCache) {
  $http.get('templates/show_order.html', { cache: $templateCache });
});

或者在构建阶段通过或连接模板。

初始延迟由路由模板请求引起。它可以通过提前缓存模板来消除

sampleApp.run(function ($http, $templateCache) {
  $http.get('templates/show_order.html', { cache: $templateCache });
});

或者在构建阶段通过或连接模板。

初始延迟由路由模板请求引起。它可以通过提前缓存模板来消除

sampleApp.run(function ($http, $templateCache) {
  $http.get('templates/show_order.html', { cache: $templateCache });
});

或者在构建阶段通过或连接模板。

我很困惑,你是在问动画延迟600毫秒的问题吗?@ewahner 600毫秒是视图之间的切换时间,可以。如果你用ctrl+R重新加载页面,然后单击一个链接,需要600多分钟。我很困惑,你是在问动画延迟600毫秒的问题吗?@ewahner 600毫秒是视图之间的切换时间,这是可以的。如果你用ctrl+R重新加载页面,然后单击一个链接,需要600多分钟。我很困惑,你是在问动画延迟600毫秒的问题吗?@ewahner 600毫秒是视图之间的切换时间,这是可以的。如果你用ctrl+R重新加载页面,然后单击一个链接,需要600多分钟。我很困惑,你是在问动画延迟600毫秒的问题吗?@ewahner 600毫秒是视图之间的切换时间,这是可以的。如果你用ctrl+R重新加载页面,然后点击一个链接,需要600多个Slooks。我将尝试并发布它,如果它对我的复杂应用程序有多个作用域,并且没有任何故障代码的话。谢谢,Tona看起来很酷。我将尝试并发布它,如果它对我的复杂应用程序有多个作用域,并且没有任何故障代码的话。谢谢,Tona看起来很酷。我将尝试并发布它,如果它对我的复杂应用程序有多个作用域,并且没有任何故障代码的话。谢谢,Tona看起来很酷。我将尝试并发布它,如果它对我的复杂应用程序有多个作用域,并且没有任何故障代码的话。非常感谢