I want to override directive ng-click: to some make some $rootscope changes before each execution of ng-click. How to do it?
相关问题
- angularJS: ui-router equivalent to $location.searc
- Separate AngularJS Controllers Into Separate Files
- Angular ngAnimate not working first time on page l
- Ionic Spinner not showing up
- Upload file to Google Cloud Storage using AngularJ
相关文章
- Passing variable through URL with angular js
- Watch entire object (deep watch) with AngularJS
- Angular ng-if change span text
- Can ng-show directive be used with a delay
- AngularJS $routeParams vs $stateParams
- Multiple parameters in AngularJS $resource GET
- How to set class/style of accordion heading in Ang
- PUT to S3 with presigned url gives 403 error
You can't override AngularJS built-in directives. However, you can define multiple directives with the same name and have them executed against the same element. By assigning appropriate
priority
to your directive, you can then control whether your directive runs before or after a built-in directive.This plunker shows how to build an
ng-click
directive that executes before the built-inng-click
does. The code is also shown below. When clicking the link, the customng-click
will run first, then the built-inng-click
does.index.html
script.js
Every directive is a special service inside AngularJS, you can override or modify any service in AngularJS, including directive
For example remove built-in
ngClick
angular support multiple directives to the same name so you can register you own
ngClick
Directivecheck out http://plnkr.co/edit/U2nlcA?p=preview I wrote a sample that removed angular built-in
ng-click
and add a customizedngClick