You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>plain text other {{variable}} plain text other</p>
//改为:
<p>plain text other <span ng-bind='variable'></span> plain text other</p>
//或
<p>plain text other <span>{{variable}}</span> plain text other</p>
dirty-checking
angular的脏检查机制(dirty-checking)是指,ng在指定事件触发后,才进入$digest cycle:
才执行$digest()或$apply()。
$digest后批量更新UI
angular是进入$digest cycle,等待所有model都稳定后,才批量一次性更新UI。这种机制能减少浏览器repaint次数,从而提高性能。
提速 $digest cycle
关键点
优化$watch
$scope.$watch(watchExpression, modelChangeCallback), watchExpression可以是String或Function。
$apply vs $digest
延迟执行
优化ng-repeat
限制列表个数
使用 track by
参见:http://www.codelord.net/2014/04/15/improving-ng-repeat-performance-with-track-by
使用单次绑定
我们都知道angular建议一个页面最多2000个双向绑定,但在列表页面通常很容易超标。
譬如一个滑动到底部加载下页的表格,一行20+个绑定, 展示个100行就超标了。
如果指令需要展示的内容之变一次的话,我们可以使用自定义的指令来代替 bindonce
在scope绑定前尽量的将数据处理小一点。
The text was updated successfully, but these errors were encountered: