angular_directive1

angular 指令多个元素multiElement

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// iterate over the attributes
//遍历所有属性 比如ng-app ng-controller
for (var attr, name, nName, ngAttrName, value, isNgAttr, nAttrs = node.attributes,
j = 0, jj = nAttrs && nAttrs.length; j < jj; j++) {
var attrStartName = false;
var attrEndName = false;

attr = nAttrs[j];//
name = attr.name;
value = trim(attr.value);

// support ngAttr attribute binding
//转换成ngController 这种
ngAttrName = directiveNormalize(name);
//ng-attr
if (isNgAttr = NG_ATTR_BINDING.test(ngAttrName)) {
//ng-attr-
name = name.replace(PREFIX_REGEXP, '')
.substr(8).replace(/_(.)/g, function(match, letter) {
return letter.toUpperCase();
});
}

var multiElementMatch = ngAttrName.match(MULTI_ELEMENT_DIR_RE);
//判断是否支持multiElement
if (multiElementMatch && directiveIsMultiElement(multiElementMatch[1])) {
attrStartName = name;
attrEndName = name.substr(0, name.length - 5) + 'end';
name = name.substr(0, name.length - 6); //去掉-start
}

nName = directiveNormalize(name.toLowerCase());
attrsMap[nName] = name;
if (isNgAttr || !attrs.hasOwnProperty(nName)) {
attrs[nName] = value;
if (getBooleanAttrName(node, nName)) {
attrs[nName] = true; // presence means true
}
}
addAttrInterpolateDirective(node, directives, value, nName, isNgAttr);
addDirective(directives, nName, 'A', maxPriority, ignoreDirective, attrStartName,
attrEndName);
}

注意到这一段代码

1
2
3
4
5
6
7
var multiElementMatch = ngAttrName.match(MULTI_ELEMENT_DIR_RE);
//判断是否支持multiElement
if (multiElementMatch && directiveIsMultiElement(multiElementMatch[1])) {
attrStartName = name;
attrEndName = name.substr(0, name.length - 5) + 'end';
name = name.substr(0, name.length - 6); //去掉-start
}

就是判断有无ng-show-start这种指令的

参考资料:
AngularJS multi-element directive
ngAttr with Angular for conditional attribute
angularJs关于指令的一些冷门属性

欢迎关注我的公众号:沉迷Spring
显示 Gitment 评论
0%