I'm implementing drag'n'drop directive. On drop I add a copy of element to my div and append ng-click
attribute to it like this:
copy.append('<button class="close" ng-click="abc()">×</button>');
For example, in controller I have
$scope.abc = function () {
alert('Hello!');
}
And it doesn't work. If I add this button on page manually it works fine.
Syntax of using ng-click directive There, the button is an element that can be replaced by any other HTML element like a link, span, paragraph, div etc.
The ng-click Directive in AngluarJS is used to apply custom behavior when an element is clicked. It can be used to show/hide some element or it can pop up an alert when the button is clicked. Parameter Value: expression: It specifies when the particular element is clicked then the specific expression will be evaluated.
For a single btn, it's ok to use ng-click or onclick in the ng-app . There is no difference between the two functions. For effective team work, you,d better to have an account with each other. In Angular apps, ng-click is recommended.
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.
copy.append('<button class="close" ng-click="abc()">×</button>');
$compile(copy)($scope);
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