mardi 17 mars 2015

generate dynamic html on ng click


Vote count:

0




I want to insert dynamic html element which contains ng-bind and directive on ng-click of a button.


Html looks like this



<body data-ng-controller="controller">
<div id="toolbox">
<label>Page Width</label>
<input type="text" data-ng-model="pageWidth" />
<input type="button" value="H1" data-ng-click="createH1()" />
</div>
<div id="editor">
<div data-ng-style="{width:pageWidth + 'px'}" data-ng-page>

</div>

</div>
</body>


Controller >



app.controller('controller', ['$scope', function ($scope) {
$scope.createH1 = function () {
document.getElementById("page").innerHTML = document.getElementById("page").innerHTML + ("<div class='h1' data-ng-h1 draggable></div>");
};
}]);


However I came to know that unless we $compile template/html they'll not work.

If I use app.directive( ngPage, ..) to add my dynamic html, it is inserting while app is started. But I want to insert only on button ng-click.


I'm new to angular js, a bit confused please help me out with this. Thanks in advance.



asked 1 min ago







generate dynamic html on ng click

Aucun commentaire:

Enregistrer un commentaire