1

i'm trying to append inside the div "otherfield", a directive element,

using while loop in the controller, who is binded to html using updateBoxes function:

HTML

<input type="number" min="2" class="form-control" id="numero_campi" ng-model="numerovoices" ng-change="updateBoxes(numerovoices)">

<div id="otherfield"></div>

JS

//DIRECTIVE
app.directive("listDirective", function() {
return {
    restrict:  'E',
    template : "<h1>This will repeated!</h1>"
};

$scope.updateBoxes = function(param){
    var el = document.getElementById('otherfield');
    var i = 0;
    while (i < param) {
        angular.element(el).append('<list-directive></list-directive>');
        i++;
    }   
}   

I'm doing right? it do't work for me...

Pds Ink
  • 765
  • 2
  • 12
  • 38

1 Answers1

1

For binding in Angular 1.x, you can use ng-bind-html for binding string as HTML.

<div ng-bind-html="thisCanBeusedInsideNgBindHtml"></div>

You can also use $sce service for that.Use $sce.trustAsHtml() in the controller to convert the html string.

$sce.trustAsHtml('<list-directive></list-directive>')

Do check this link for more information

Community
  • 1
  • 1
Muhammed Neswine
  • 2,028
  • 1
  • 20
  • 20