【发布时间】:2015-06-23 04:29:35
【问题描述】:
我正在使用带有角度的传单地图并添加了图例。为了改变地图的外观,我在视图加载了 $timeout-method 之后操作了 DOM。图例应该是可点击的,以选择哪些项目应该出现在地图上。因此,当单击图例中的一项时,我尝试发出警报。为此,我将项目更改为一个按钮,只是为了确定。但是按钮单击不起作用,因为它不知道方法。
有人知道如何在被操纵的 DOM 对象上调用 ng-click 方法吗?
这是我的一些代码:
controller.js
//initiating of the map happend before
//now loading of the markers and manipulating of the map
function activate() {
projectService.getMarkers(vm, 'projectsData');
bindEventListener();
$timeout( function() {
getLegendElement();
});
}
//manipulating of the legend element to make a button with a ng-click
function getLegendElement() {
var element = document.getElementsByClassName("legend leaflet-control");
element[0].children[0].innerHTML = '<button ng-click="showAlert()">ok</button>';
}
//showing the alert
$scope.showAlert = function(){
$window.alert("foo");
}
【问题讨论】:
标签: javascript angularjs dom click dom-manipulation