angular中的自定义指令-灵析社区

花影流年

``` angularjs minesweeper.directive('ngRightClick', function($parse) { return function(scope, element, attrs) { var fn = $parse(attrs.ngRightClick); element.bind('contextmenu', function(event) { scope.$apply(function() { event.preventDefault(); fn(scope, {$event:event}); }); }); }; }); ``` 如上代码,解释说是自定义ngRightClick指令,但是首先不能理解它的意思,再一个自定义指令不应该是下面这种形式吗: ``` angularjs minesweeper.directive("mineGrid",function(){ return { restrict:'E', replace:false, templateUrl:'./templates/mineGrid.html' } }); ``` 求指教

阅读量:148

点赞量:0

问AI
万码用户
首先自定义右键不是自定义元素,不应约束为element,更不会有HTML。直接返回function是直接返回link function的简写,自定义右键应该约束为属性。