angular.js - custom directives in angular
phpcn_u1582
phpcn_u1582 2017-05-27 17:44:42
0
2
1309
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});
                });
        });
    };
});

The above code explains that it is a custom ngRightClick instruction, but first of all I can’t understand its meaning. Shouldn’t a custom instruction be in the following form:

minesweeper.directive("mineGrid",function(){
    return {
        restrict:'E',
        replace:false,
        templateUrl:'./templates/mineGrid.html'
    }
});

Please give me some advice

phpcn_u1582
phpcn_u1582

reply all(2)
phpcn_u1582

First of all, the custom right-click is not a custom element and should not be constrained to element, let alone HTML. The direct return function is the abbreviation of the direct return link function, and the custom right button should be constrained to an attribute.

淡淡烟草味

This is using angular’s ​​built-in service $parse. It is recommended to read this article AngularJS insider detailed explanation Directive

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template