angular学习笔记

1、forEach

     arr:参数是key,index

     json:与jquery相反,参数是value,key
2、str-->json

      JSON.parse()       angular.fromJson()
    json-->str

          JSON.stringify()      angular.toJson() 后面跟一个true,会转换成json形式的字符串,方便查看

3、copy(),extend(),merge()的区别

  angular.copy(source, [destination]);

  1、如果destination省略,则创建出一个对象或数组

  2、如果destination存在,删除destination里的所有属性,把source里的所有属性深copy过来

  3、如果source不是对象或数据(如:null或undefined),直接return source

  4、如果source和destination一样,则抛出异常

 

  angular.extend(dst, src);

  和jquery中的$.extend(dst,src)一样

 

  angular.merge(dst,src);

  和jquery中的$.extend(true,dst,src)一样

 

  注:copy和(extend|merge)中的参数是相反的。

4、angular.identity(value)  直接返回传入的值,即value

 

function transformer(transformationFn, value) {
  return (transformationFn || angular.identity)(value);
};
//相当于如下
if (transformationFn){
  return transformationFn(value)
} else {
    return value
}

 5、angular.noop(),什么都不操作

function foo(callback) {
  var result = calculateResult();
  (callback || angular.noop)(result);
}
//有callbak,则执行callback函数,没有则什么都不操作

6、$filter('orderBy')(array,expression,reverse)

第三个参数,排序是正序还是反序,不写或者false为正序,true为反序

7、ng-repeat

$index :从0开始

$even:第一个偶数为true

8、$filter('filter')(array,expression,comparator)

array:souce

expression:

  1、string: 字符串或者对象字符串属性

        前面加上“!”会取反向

  2、object:{name:'M',phone:'1'},会找name为M并且phone为1,只能找同级的

        {$:'text},会找任意属性为text,可以找到嵌套的

        {name:'!M'},会找name不为M的

  3、function(value,index,array){}: 

    value为每一个值

    index为索引

    array为整个大的数组

    return true为找到

comparator:

  1、function(actual,expected){}:

    true为找到,actual为每次进来的值,有可能是string或者object,expected为希望找到的值(即:第二个参数中的expression)

  2、true

    严格,即return angular.equals(actual,expected),全等(区别大小写)

  3、false|undefined

    模糊,不区分大小写

 

        

 

 

 

 

 

posted @ 2016-02-03 15:07  joya  阅读(259)  评论(0编辑  收藏  举报