关于隔离范围属性的AngularJS文档

前端之家收集整理的这篇文章主要介绍了关于隔离范围属性的AngularJS文档前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
是否有任何AngularJS文档提供了一个直接明确的方法列表,用于处理具有隔离范围的指令中的属性

directive guide触及=的使用,但没有列出用于绑定的其他选项.

到目前为止,我知道(通过混合来源):

scope: {
   myAttr1: '=attr1',myAttr2: '=?attr2',myAttr3: '@attr3',myAttr4: '&attr4'
},
看看编译服务: http://docs.angularjs.org/api/ng.$compile

The ‘isolate’ scope takes an object hash which defines a set of local scope properties derived from the parent scope. These local properties are useful for aliasing values for templates. Locals definition is a hash of local scope property to its source:

@ or @attr – bind a local scope property to the value of DOM attribute. The result is always a string since DOM attributes are strings. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localName:’@myAttr’ },then widget scope property localName will reflect the interpolated value of hello {{name}}. As the name attribute changes so will the localName property on the widget scope. The name is read from the parent scope (not component scope).

= or =attr – set up bi-directional binding between a local scope property and the parent scope property of name defined via the value of the attr attribute. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localModel:’=myAttr’ },then widget scope property localModel will reflect the value of parentModel on the parent scope. Any changes to parentModel will be reflected in localModel and any changes in localModel will reflect in parentModel. If the parent scope property doesn’t exist,it will throw a NON_ASSIGNABLE_MODEL_EXPRESSION exception. You can avoid this behavior using =? or =?attr in order to flag the property as optional.

& or &attr – provides a way to execute an expression in the context of the parent scope. If no attr name is specified then the attribute name is assumed to be the same as the local name. Given and widget definition of scope: { localFn:’&myAttr’ },then isolate scope property localFn will point to a function wrapper for the count = count + value expression. Often it’s desirable to pass data from the isolated scope via an expression and to the parent scope,this can be done by passing a map of local variable names and values into the expression wrapper fn. For example,if the expression is increment(amount) then we can specify the amount value by calling the localFn as localFn({amount: 22}).

猜你在找的Angularjs相关文章