Event delegates: If the child elements are constantly changing and the number is numerous, you need to repeatedly bind events and waste resources. You can then bind the event to the parent element and then find the event object that triggered the event through Event.target. Then get the data you need to execute the binding event.
In angular, the event object cannot be obtained directly through Event.target, but must be obtained by passing the parameter $event and then adding a parameter to the event that is bound in the component in the following code:
In HTML:
<div class= "Replytext" ng-click= "DeleteText ($event)">
<p ng-repeat= "Val in discuss" >
<span><b>{{val.name}}: </b></span>
<span>{{val.text}}</span>
<span class= "Time" >{{val.time}} <a href= "javascript:;" id={{val._id}}> Delete </a></span>
</p>
</div>
JS in:
$scope. DeleteText = function ($event) {
var id = $event. target.id;
Console.info (ID);
var bool = confirm ("Really want to delete?"). ");
if (bool) {
$http. Delete ("/delete/reply/text/" + ID). Success (function (data) {
if (data.tips) {
GetDate ();
}
else{
Alert ("Delete failed");
}
});
}
};
Event delegate for Angular