From 1st view seems like data-ng-click
can pass some data as argument to method should be invoked during pressing on button.
But I don't see the difference.
I have followed snippets of code:
HTML
<input type="button" value="Fess" ng-click="toggle(2)">
OR
<input type="button" value="Fess" data-ng-click="toggle(2)">
JS
$scope.toggle = function (valueS) { alert(valueS); }
Both work.
Thanks,
The difference is simple - there is absolutely no difference between the two except that certain HTML5 validators will throw an error on a property like ng-app , but they don't throw an error for anything prefixed with data- , like data-ng-app .
Another significant difference between ng-click and onclick is the execution context. Code inside an onclick attribute executes against the global window object, while an expression inside of ng-click executes against a specific scope object, typically the scope object representing the model for the current controller.
There is no difference between ng-model and data-ng-model if you see in terms of AngularJs. Actually, 'data' used as prefix to validate HTML5 validation. So, it is good practice to use data-ng-model , however, you can use ng-model as well. There is no problem in that also.
The AngularJS ng-click directive facilitates you to specify custom behavior when an element is clicked. So, it is responsible for the result what you get after clicking. It is supported by all HTML elements.
They are the same thing. You can use data-ng-click
to make a valid html.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With