加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 10:16:55 所属栏目:安全 来源:网络整理
导读:是否有任何AngularJS文档提供了一个直接明确的方法列表,用于处理具有隔离范围的指令中的属性? directive guide触及=的使用,但没有列出用于绑定的其他选项. 到目前为止,我知道(通过混合来源): scope: { myAttr1: '=attr1',myAttr2: '=?attr2',myAttr3: '@at
是否有任何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}).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读