angularjs和ionic性能优化(2)
来源:互联网 发布:电脑跳舞毯软件 编辑:程序博客网 时间:2024/04/30 06:19
angular 性能优化
使用$watchCollection(obj, listener),
不要使用$watch()
或者$watchGroup()
;使用one-time binding
{{::user.first_name}}
使用Track by
以前的用法ng-repeat="user in users"
修改后的用法ng-repeat="user in users track by user.id"
如果users有id的话
或者ng-repeat="user in users track by $index"
如果没有id不要使用console.log(),而是用$log
The
$log
service has several log levels.info
.debug
and.error
.禁用dubug
angular.module('yourModule').config(function($compileProvider) { if (/* test if in production */) { $compileProvider.debugInfoEnabled(false); }});
AngularJS by default adds scope references to the DOM for tools such as angularjs-batarang to work. This has an impact on your application performance.
使用lodash库的_.forEach遍历,他的效率是angular foreach的4倍。
动画,参考这篇文章http://www.bennadel.com/blog/2935-enable-animations-explicitly-for-a-performance-boost-in-angularjs.htm。据说有显著提升
ionic性能优化
- 使用原生滚动方式
angular.module('yourModule').config(function($ionicConfigProvider) { $ionicConfigProvider.scrolling.jsScrolling(false);});
参考:http://blog.ionic.io/native-scrolling-in-ionic-a-tale-in-rhyme/
- 使用collection repeat
<ion-content> <ion-item collection-repeat="item in items"> {{item}} </ion-item></ion-content>
参考:http://ionicframework.com/docs/api/directive/collectionRepeat/
- 无限滚动
指令允许调用一个函数,当页面到底部或靠近底部的时候。
<ion-content ng-controller="MyController"> <ion-list> .... .... </ion-list> <ion-infinite-scroll on-infinite="loadMore()" distance="1%"> </ion-infinite-scroll></ion-content>
使用one-time binding,track by和native scrolling组合有最好的性能。
缓存试图
angular.module('yourModule').config(function($ionicConfigProvider) { $ionicConfigProvider.views.maxCache(5);});
$stateProvider.state('myState', { cache: false, url : '/myUrl', templateUrl : 'my-template.html'});
<ion-view cache-view="false">
试图缓存事件
$scope.$on('$ionicView.loaded', function(){});$scope.$on('$ionicView.enter', function(){});$scope.$on('$ionicView.leave', function(){});$scope.$on('$ionicView.beforeEnter', function(){});$scope.$on('$ionicView.beforeLeave', function(){});$scope.$on('$ionicView.afterEnter', function(){});$scope.$on('$ionicView.afterLeave', function(){});$scope.$on('$ionicView.unloaded', function(){});
正确使用事件加载数据可以优化程序
- angularjs和ionic性能优化(2)
- ionic性能优化(1)
- phonegap 性能优化 以及 phonegap + Angularjs + ionic 移动 app 开发介绍
- angularjs 和 ionic 教程网址
- angularjs 性能优化 转载
- AngularJS 性能优化二三事
- Angularjs 性能优化
- ionic的性能优化和ionic-native-transitions插件的参数调优等
- ionic ,angularJS
- ionic和angularjs开发app学习笔记
- Ionic+AngularJS登录和注册带验证
- ionic和AngularJs 项目问题笔记
- phonegap (ionic+angularjs) 环境搭建
- AngularJS中星级的评价(ionic)
- Ionic + Angularjs + Cordova(Ionic2环境搭建)
- Angularjs+ionic 学习(一):Angularjs常用指令
- angularjs和ionic学习博客和问题记录
- Ionic开发 (性能很差吗?也许这些优化手段你没用过)
- css中position属性的static,relative,absolute,fixed简要说明
- c++ lambda表达式
- Linux下安装zookeeper
- Javascript比较运算符详解
- 引用类型
- angularjs和ionic性能优化(2)
- 设置marker拖拽并根据坐标,反地理获取地址详情
- spring MVC 管理HttpClient---实现在java中直接向Controller发送请求
- 【PAT】1027. Colors in Mars
- 使用系统相机应用
- java集合
- 学习笔记之HTML5入门教程
- 哈理工 1943
- Android_android开发:介绍