【发布时间】:2014-03-10 16:15:17
【问题描述】:
我想包含从 ajax 请求加载的 html 数据,并在我的 html 数据中触发图像的点击事件。我知道这在 SPA 世界中是错误的,但我需要显示来自 wysiwyg 编辑器的数据...
这是用 jQuery 重构的代码:
$http.get('Help/Help/GetHelp', { params: { helpId: contentKey } }) .success(function(data) {
if (data.success) {
// viewData is html from wysiwyg editor
$scope.viewData = data.viewData;
// HERE is problem because now images isn't in DOM. This is too early
angular.element('div#content').find('img').click(function () {
// Show image in gallery
});
} else {
$scope.viewData = "";
}
});
但它不起作用,因为当我在它们上触发点击事件时,图像不在 DOM 中......解决这个问题的最佳做法是什么?
谢谢!
【问题讨论】:
-
还有这个用于事件绑定:stackoverflow.com/a/14695299/405398
标签: javascript html angularjs