
angular1
shidaping
这个作者很懒,什么都没留下…
展开
-
angular1中使用track by优化ng-repeat效率
track by是angular1.2后新加入的。ng-repeat会为每一次元素加上一个hashkey $$hashKey来识别每一个元素,当我们从后端重新获取数据时,即使数据完全一样,但是由于hashKey不一样,angular会删除之前的所有dom,重新生成新的dom。这样效率就会大大降低。可以理解为ng-repeat默认是 track by $$hashKey的。所以,我们应该使用一些不会原创 2016-07-12 14:32:46 · 7721 阅读 · 2 评论 -
angular使用bootstrap方法手动启动
要启动一个angular应用,可以使用ng-app指令,也可以调用bootstrap方法手动启动。先看一下angular的bootstrap方法。angular.bootstrap(element, [modules], [config]);element(必需)。要启动angular的根节点,一般为document,也可以是其他的的html的dom。modules(数组,可选原创 2016-08-29 11:37:56 · 7787 阅读 · 0 评论 -
angular表单验证
angular表单验证主要涉及以下指令name:表单字段的属性名ng-pattern:正则表达式ng-required:必填required:必填ng-minlength:最小长度ng-maxlength:最大长度ng-trim:是否自己裁掉头尾空白,默认为true看例子:原创 2016-08-29 14:39:03 · 701 阅读 · 0 评论 -
angular中$q.all用法
$q.all是用于执行多个异步任务进行回调,它可以接受一个promise的数组,或是promise的hash(object)。任何一个promise失败,都会导致整个任务的失败。例1:接受一个promise的hash(object): var app = angular.module('app',[]); app.controller(原创 2016-09-01 13:49:06 · 11779 阅读 · 0 评论 -
angular1中的事件,以及$broadcast,$emit的区别
angular1中,使用$scope.$on(事件名,处理函数)可以接收事件,使用$scope.$broadcast(事件名,数据)或者$scope.$emit(事件名,数据)可以触发事件。那$broadcast和$emit有什么区别呢。他们的区别在于,$broadcast会向下广播事件即只有本身和子controller可以收到这个事件,而$emit向上广播事件,即只有本身和父controller原创 2016-08-25 14:41:59 · 2631 阅读 · 0 评论 -
angular directive详解之transclude
directive的transclude是做什么的呢?英文原文的解释是:transclude makes the contents of a directive with this option have access to the scope outside of the directive rather than inside.意思是transclude可以使direc原创 2016-11-11 16:43:30 · 1613 阅读 · 0 评论 -
angular directive详解之replace
replace属性为true时,会替换directive指向的元素;为false时将directive的内容作为子元素插入到directive指向的元素。默认为false。看例子: var app = angular.module('app', []); app.directive('myDirective', [fun原创 2016-11-11 17:55:21 · 2961 阅读 · 0 评论 -
angular directive详解之scope
scope是控制directive中的变量与引用directive的controller之间的关系的重要属性。其有四种修饰符=表示共享某个变量 Two-way model binding&表示共享某个方法(回调) Callback method binding@表示传递某个值 Attribute string binding如果不写scope,默认与controller共享scop原创 2016-11-14 16:49:37 · 1401 阅读 · 0 评论 -
angular1 ui-router使用
.nav>a.active{ color: red; } router1 router2 var app = angular.module('app',['ui.router']); app.config(['$stateProvider', '$urlRouterProvider', function($state原创 2017-01-09 11:11:10 · 1260 阅读 · 0 评论