I'm learning AngularJS and I have a problem that I can not solve.
I have a function inside a controller that is inside a module. This function is responsible for assembling an accordion element with several items:
$scope.montaAccordion = function(dados){
var elemento = "";
for(var i=0; i < dados.length; i++){
elemento += "<div class='accordion-group' indice='collapse"+dados[i].AtributoVariacao.id+"'>";
elemento += "<div class='accordion-heading'>";
elemento += "<a class='accordion-toggle' data-toggle='collapse' data-parent='#sidebar-accordion' href='#collapse"+dados[i].AtributoVariacao.id+"'>";
elemento += "<i class='icon-reorder'></i>"+dados[i].Variacao.variacao+":: "+dados[i].AtributoVariacao.atributo;
elemento += "</a>";
elemento += "</div>";
elemento += "<a href='#' class='bt-del-atributo' style='float:right; margin: -33px 7px 0 0;'>";
elemento += "<i class='fa fa-times fa-2x'></i>";
elemento += "</a>";
elemento += "<div id='collapse"+dados[i].AtributoVariacao.id+"' class='accordion-body collapse'>";
elemento += "<div class='accordion-inner'>";
elemento += "<div class='control-group' data-fieldname='preco-diferenciado' style='padding:0;'>";
elemento += "<div class='controls'>";
elemento += "<label class='control-label'>Esta variação possui um preço diferenciado?</label>";
elemento += "<input type='text' name='preco-diferenciado-"+dados[i].AtributoVariacao.id+"' class='span12' value='' placeholder=''>";
elemento += "</div><br />";
elemento += "<button type='button' class='btn btn-info' ng-click='salvaPrecoDiferenciado("+dados[i].AtributoVariacao.id+")'>Salvar</button>";
elemento += "</div>";
elemento += "</div>";
elemento += "</div>";
elemento +="</div>";
}
$('#sidebar-accordion').html(elemento);
}
But in the excerpt:
elemento += "<button type='button' class='btn btn-info' ng-click='salvaPrecoDiferenciado("+dados[i].AtributoVariacao.id+")'>Salvar</button>";
ng-click does not work. I think it's a problem in the scope, or where I enter this DiffPrev () function.
I declare the function in the same controller:
$scope.salvaPrecoDiferenciado = function(id){
alert(id);
}
and did not work. Can anyone help me?