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>。就是将首字母小写,每个名字部分首字母大写的形式转化为通过-来连接小写部分的形式。

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

    原文作者:chenatu
    原文地址: https://segmentfault.com/a/1190000007018852
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞