$解析AngularJs服务,如官方文档所述

时间:2014-02-22 19:41:39

标签: angularjs

我参考了AngularJS $ parse服务,如以下文档所述: http://docs.angularjs.org/api/ng/service/$parse

我不熟悉AngularJs文档,想知道这些是什么意思:

  • {object=}
  • {?function(context, value)}

=符号在AngularJs文档的上下文中意味着什么?

?标记在AngularJs文档的上下文中意味着什么?

2 个答案:

答案 0 :(得分:3)

这些是从Closure Compiler注释(https://developers.google.com/closure/compiler/docs/js-for-compiler)派生的注释。

答案 1 :(得分:2)

  • {object=}

这只是本地对象的表示法。

本地对象可能如下所示:{local:{value:'isSet'}}

其中object(本地)为={value:'isSet'}

这只是表明该对象必须被命名为本地对象的键值对。

这是一个例子。

var context = { stuff:null },
    locals = { local: { value:'isSet' }, local1:'!' },
    parseFunction = $parse("stuff = local.value + local1"),
    result = parseFunction(context,locals);

console.log(context); // -> Object { stuff: 'isSet!' }
console.log(result); // -> 'isSet!'

至于{?function(context, value)}

这表明您需要在使用之前检查该属性是否存在(因为它可能已定义,也可能未定义)。

在上述代码的情况下。因为它不是'可分配的'表达式

parseFunction.assign === undefined // true

一般来说'?'表示可能存在或不存在的事情。

希望这有帮助!