Check out my custom Angular directive code below, which generates div elements:
function footerDirective($compile){
return {
link: function(scope,elements,attributes){
function createDiv(content,cname,callback){
var new_div=document.createElement("div");
new_div.setAttribute("ng-click", callback);
$compile(new_div)(scope);
new_div.innerHTML=content;
new_div.className=cname;
elements[0].appendChild(new_div);
}
for (var i=0;i<5;i++) {
createDiv(i,"class-numbers","gallery.clickPage()");
}
}}}
In the code snippet above, gallery.clickPage
refers to a Controller method. It functions properly as is. However, I am trying to pass i as an argument into gallery.clickPage
, like so:
gallery.clickPage.bind(this,i)
Unfortunately, when I attempt to pass this into the createDiv
function, it does not work. How can I make this modification successfully?