AngularJS加载模板缓慢 [英] Angularjs slow to load templates

查看:49
本文介绍了AngularJS加载模板缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有些东西并没有真正做很多,但确实需要花费最长的时间来加载.我已将代码写下来供大家查看:

I have some which doesn't really do much, still it does really take the longest time to load. I have written the code down for you all to see:

app.js

var simple = "simple test";
  angular.module('CRTapp', []).controller('ItemController', function() {
    this.item = simple;
});

index.html

<div id="item" ng-controller="ItemController as item">
{{item.simple}}  
</div>

有时候人们不得不等待近一秒钟才能看到:

Sometimes people are having to wait nearly a second to see:

{{item.simple}}

之前

simple test

出现,但是对于某些人来说,这是一个很长的时间.等待对我来说还可以,但是有时Jake会变得不耐烦,所以我可以根据需要让HTML页面缓慢加载,但是我不希望我的Stretchy先生在他自己的特别网站上看到一个模板之前在他的糖果之旅中看到一个模板时感到难过王国.

appears but this is a very long time for some of you to have to wait. Waiting is ok for me but sometimes Jake gets impatient so I can make the HTML page load slowly if you like, but I do not want my Mr Stretchy to become sad when he sees a template before his own special website for his adventures in the Candy Kingdom.

推荐答案

此延迟是角度库解析HTML的时间.您可以改用ng-bind:

This delay is the time angular library gets to parse your HTML. You can use ng-bind instead:

<div id="item" 
     ng-controller="ItemController as item"
     ng-bind="item.simple">
</div>

这样,当您的页面加载角度时,您的页面就不会受到污染.

This way, your page won't get polluted while angular loads its content.

这篇关于AngularJS加载模板缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆