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...

1
  • Does it do anything? Do you get any errors? Commented Mar 30, 2017 at 16:37

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.