I have created dynamic div on the basis of an array values using jquery. It works fine,The following is the code for jquery,
$(document).ready(function () {
var i = 1;
var arr = ["a", "b", "c"];
/*arr=;*/
//arr = doc.slice();
$(window).load(function () {
alert(arr[1] + ":" + arr.length);
for (i = 0; i < arr.length; i++) {
var ele = document.createElement("div");
ele.setAttribute("id", "child" + i);
ele.setAttribute("class", "span4 greenDark");
ele.innerHTML = '<object type="text/html" data="iindex.html" ></object>';
document.getElementById("mydiv").appendChild(ele);
}
});
});
But I need to do this same function in angular js ng-init method call. But the angular code didint create any div. I have tried the following code,
var arr = ["a", "b", "c"];
alert("load" + arr);
for (i = 0; i < arr.length; i++) {
alert("load" + arr[i]);
var ele = document.createElement("div");
ele.setAttribute("id", "child" + i);
ele.setAttribute("class", "span4 greenDark");
ele.innerHTML = '<object type="text/html" data="iindex.html" ></object>';
// angular.element(document.getElementById("mydiv").appendChild(ele));
angular.element(document.getElementById('mydiv')).append($compile("<div><button class='btn btn-default' data-alert=" + scope.count + ">Show alert #" + scope.count + "</button></div>")(scope));
}
I need help.