`M` 在 restrict AngularJS 选项中代表什么?
What does `M` stand for in the restrict AngularJS option?
M
在限制 AngularJS 选项中代表什么?
从 AngularJS Developer Guide - Directives 文档中我看到:
The restrict option is typically set to:
...
'C' - only matches class name
'M' - only matches comment
但是为了避免记住C
是给class而M
是给注释的,我想明白为什么要用M
。
我在互联网上没有找到任何相关信息。我的猜测是 m
是单词 comment
中 c
之后的下一个辅音字母,并且由于 c
已被评论采用,因此 m
是用过。
这完全符合它所说的 - 允许将指令与评论相匹配。
因此:
directive('yourDirective', function() {
return {
restrict: 'M',
template: '<span>Something in here</span>'
};
});
可以这样使用:
<!-- directive: your-directive -->
AngularJS支持注释指令,但最好不要使用它们。
来自文档:
Best Practice: Prefer using directives via tag name and attributes over comment and class names. Doing so generally makes it easier to determine what directives a given element matches.
Best Practice: Comment directives were commonly used in places where the DOM API limits the ability to create directives that spanned multiple elements (e.g. inside elements). AngularJS 1.2 introduces ng-repeat-start
and ng-repeat-end
as a better solution to this problem. Developers are encouraged to use this over custom comment directives when possible.
有关详细信息,请参阅
M
在限制 AngularJS 选项中代表什么?
从 AngularJS Developer Guide - Directives 文档中我看到:
The restrict option is typically set to:
...
'C' - only matches class name
'M' - only matches comment
但是为了避免记住C
是给class而M
是给注释的,我想明白为什么要用M
。
我在互联网上没有找到任何相关信息。我的猜测是 m
是单词 comment
中 c
之后的下一个辅音字母,并且由于 c
已被评论采用,因此 m
是用过。
这完全符合它所说的 - 允许将指令与评论相匹配。
因此:
directive('yourDirective', function() {
return {
restrict: 'M',
template: '<span>Something in here</span>'
};
});
可以这样使用:
<!-- directive: your-directive -->
AngularJS支持注释指令,但最好不要使用它们。
来自文档:
Best Practice: Prefer using directives via tag name and attributes over comment and class names. Doing so generally makes it easier to determine what directives a given element matches.
Best Practice: Comment directives were commonly used in places where the DOM API limits the ability to create directives that spanned multiple elements (e.g. inside elements). AngularJS 1.2 introduces
ng-repeat-start
andng-repeat-end
as a better solution to this problem. Developers are encouraged to use this over custom comment directives when possible.
有关详细信息,请参阅