2
Good night I have this method
$scope.register_popup = function(id, name)
{
for(var iii = 0; iii < popups.length; iii++)
{
//already registered. Bring it to front.
if(id == popups[iii])
{
Array.remove(popups, iii);
popups.unshift(id);
$scope.calculate_popups();
return;
}
}
var element = '<div class="popup-box chat-popup" id="'+ id +'">';
element = element + '<div class="popup-head">';
element = element + '<div class="popup-head-left">'+ name +'</div>';
element = element + '<div class="popup-head-right"><a href="javascript:;" ng-click="close_popup(\''+ id +'\');">✕</a></div>';
element = element + '<div style="clear: both"></div></div><div class="popup-messages"></div></div>';
document.getElementById("chat").innerHTML = document.getElementById("chat").innerHTML + element;
popups.unshift(id);
$scope.calculate_popups();
}
I mean, I have a dynamically created div. Look at this line:
element = element + '<div class="popup-head-right"><a href="javascript:;" ng-click="close_popup(\''+ id +'\');">✕</a></div>';
in ng-click, I call one more method, which in this case would be:
$scope.close_popup = function(id)
{
for(var iii = 0; iii < popups.length; iii++)
{
if(id == popups[iii])
{
Array.remove(popups, iii);
document.getElementById(id).style.display = "none";
$scope.calculate_popups();
return;
}
}
}
But nothing happens, even if I put a console.log in this method does not show me anything, I believe it is because it is created dynamically. How can I fix this?
Hello Daniel, I think I understand what you’re trying to do in the code above, but unfortunately you’re doing it in the wrong place. The best way for you to dynamically create this element is to create a DIRECTIVE. This way it will be much simpler to pass the HTML template that should be used and also much simpler to "bind" the click on the element. If you create a Plunker or Jsfiddle with the rest of the code I can help you.
– Denison Luz