How to call the triggerHandler
method for dynamically added nodes in Angular?
My nodes are dynamically generated based on a table:
<a class="btn btn-default J_Local" href="javascript:void(0);" id="J_MapImg_{{my.sku_val_id}}" ng-click="uplod($event)"><span>本地上传</span></a>
The click event is as follows:
$scope.uplod = function(obj){
supload.init({
button: ''+obj.currentTarget.id+'', uploaded: function (uploader, file, response) {
if (response.code == 1){
layer.msg(response.msg);
}
else {
$('#'+obj.currentTarget.id).siblings("p.preview").html("<img src='" + response.src + "' width='20' height='20'/>");
}
}
});
$('#'+obj.currentTarget.id+'').off("click");
}
But the dynamically generated image calls my image upload and requires double-clicking to be punished. I want to have it automatically trigger a click when a click is generated. How to achieve this?
漂亮男人2017-05-15 17:10:56
If it isangularjs
, it is wrong to mix jQuery in it
For your scenario, there is no need to dynamically insert html code, and master the following knowledge points
angular.module('app', [])
.filter("trustUrl", ['$sce', function ($sce) {
return function (recordingUrl) {
return $sce.trustAsResourceUrl(recordingUrl);
};
}])
function($scope, $ajax) {
$scope.src = null;
$scope.upload = function() {
$ajax.post(...., function(response){
$scope.src = response.src;
$scope.$apply(); //通知更改了
}
}
}
<img src="{{src || 'http://...../upload.jpg'|trustUrl}}" ng-click="upload()">
淡淡烟草味2017-05-15 17:10:56
If it is jquery, you need to use the $().on("click",function(){}) form