1

I have this code on my controller:

angular.module('reporteadorApp')
    .controller('sidebarCtrl', ['$scope', '$http', '$cookies', '$sce', function ($scope, $http, $cookies, $sce) {
        $scope.codeControles = '<div class="row"><div class="col-sm-12">'
        $scope.codeControles += '<div class="form form-group"><label>' + asignarListaControles.nombreControl + '</label><select class="form form-control" ng-model="' + asignarListaControles.variable1 + '"></select></div>';
        $scope.codeControles += '</div></div>';
        $scope.codigoHTML = $sce.trustAsHtml($scope.codeControles);
}]);

Then in my HTML:

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

I'm trying get the values of ng-models inserted on my view, but i can't, angular returns undefinided. Whats the problem?!. If i add an input manually and assign an ng -model, can get its value.

Also I can not add data to this select using ng-repeat

Thanks

Luis
  • 54
  • 4
  • On the chrome editor i check the html has been created successfully – Luis Sep 29 '15 at 23:49
  • anything inside `ng-bind-html` isn't compiled by angular therefore directives will not work inside it. You seem to be creating a custom directive and should just use your html as `template` option in a directive. For your use case it is very easy to create one. – charlietfl Sep 30 '15 at 00:14
  • You can show me an example please? I search somethin about $compile :( – Luis Sep 30 '15 at 13:36
  • Just create a directive instead of `ng-bind-html` and use that html string as `template`. `
    `
    – charlietfl Sep 30 '15 at 13:48

1 Answers1

0

Finally i resolve my problem with this:

var htmlToInsert = $compile('<div>' + $scope.codeControles + '</div>')($scope);
$('#yourDivName').html(htmlToInsert);

Then in my HTML:

<div id="yourDivName"></div>

;)

Luis
  • 54
  • 4