AngularJS 1.4.8笔记(持续更新)

FAQs

1. 如何在Angular中使用jQuery?

  • jQuery 2.1+ for Angular 1.4 (jQuery 1.x不是Angular 1.4的官方支持版本)
  • 在加载Angular相关scripts之前加载jQuery

Best Practices

1. ngSrc over src for images

对于标签,用ng-src="{{imageUrl}}"代替src="{{imageUrl}}"。目的是防止浏览器在页面加载的时候请求错误的图片地址。其原理是“延迟加载”,即等到HTML模板编译完成之后再去请求正确的图片地址。

2. ngBind and ngBindTemplate over Angular Expression

...

原理是在HTML模板(元素)正式填充完成之前隐藏该元素,这样可以避免在页面加载时c出现“闪屏”现象,即包含Angular表达式{{expression}}的原始HTML内容一闪而过。

It is preferable to use ngBind instead of {{expression}} if a template is momentarily displayed by the browser in its raw state before Angular compiles it. Since ngBind is an element attribute, it makes the bindings invisible to the user while the page is loading.

另一种方式是通过对局部元素使用ngCloak来避免元素裸奔。

...

The ngCloak directive is used to prevent the Angular html template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the html template display.

你可能感兴趣的:(AngularJS 1.4.8笔记(持续更新))