angularjs directive和component命名规则的坑

前端之家收集整理的这篇文章主要介绍了angularjs directive和component命名规则的坑前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

angularjs directive和component命名规则的坑

今天才发现angularjs doc中directive有这么一段

Normalization Angular normalizes an element's tag and attribute name
to determine which elements match which directives. We typically refer
to directives by their case-sensitive camelCase normalized name (e.g.
ngModel). However,since HTML is case-insensitive,we refer to
directives in the DOM by lower-case forms,typically using
dash-delimited attributes on DOM elements (e.g. ng-model).

The normalization process is as follows:

Strip x- and data- from the front of the element/attributes. Convert
the :,-,or _-delimited name to camelCase.

这段其实也讲了html命名转化规则

比如我定义一个component名字为cpuLoad,在模板引用中,我们需要这样引用<cpu-load>。就是将首字母小写,每个名字部分首字母大写的形式转化为通过-来连接小写部分的形式。

命名的时候得注意这个隐含的转化规则,真是个坑

猜你在找的Angularjs相关文章