搜尋

首頁  >  問答  >  主體

angular.js - directive命名規則?

directive只能由小寫字母組成嗎?

.directive('名称', function() {
    return {
        restrict: 'AE',
        template: '<p>Hi there</p>',
        replace: true
    };
});

例如,
hello ok
helloA not work
Hello not work
hello_a not work
hello-a not work

我的要一個詞組命名怎麼辦?

phpcn_u1582phpcn_u15822825 天前808

全部回覆(1)我來回復

  • 迷茫

    迷茫2017-05-15 16:54:18

    採用駝峰式命名
    如:hello A not work
    命名為:helloANotWork

    詳細規則:
    在html中使用以下方式

    html<my-new-directive></my-new-directive>
    

    但是定義指令時需要這樣

    javascriptmyApp.directive("myNewDirective", function(){...});
    

    回覆
    0
  • 取消回覆