转自:https://www.cnblogs.com/best/tag/Angular/html
关于自定义指令的命名,你能够随便怎么起名字都行,官方是推荐用[命名空间-指令名称]这样的方式,像ng-controller。不过你可千万不要用 ng-前缀了,防止与系统自带的指令重名。另一个需知道的地方,指令命名时用驼峰规则,使用时用-分割各单词。如:定义myDirective,使用时 像这样:<my-directive>。app
这里列出directive的合法命名:dom
- ng:bind
- ng-bind
- ng_bind
- x-ng-bind
- data-ng-bind
- app.directive('fractionNum',function(){
- return {
- link : function(scope, elements, attrs, controller){
- elements[0].onkeyup = function(){
- if(isNaN(this.value) || this.value<1 || this.value>10){
- this.style.borderColor = 'red';
- }
- else{
- this.style.borderColor = '';
- }
- };
- }
- };
- });
- 分数:<input type="text" ng-model="question.fraction" fraction-num /><br />