J
J
jack3d2015-10-14 12:07:25
Angular
jack3d, 2015-10-14 12:07:25

Is it correct to replace ng-click with your own directive in angularjs?

For example, deleting a comment should be like this:

<button ng-click="vm.deleteComment(comment.id)">Delete</button>

and further in the controller there are already requests to api
or so, through the directive
<button data-delete-post >Delete</button>
and further in the directive requests to api.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Radiks Alijevs, 2015-10-14
@dedalik

If the method
will only be used in one controller, then ng-click can be used, and if the method will be used in multiple controllers, it's better to make a directive so as not to duplicate the method in each $scope.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question